Here is a simple example showing how you can do this:
manifest.json:
{ "name": "TabCapture", "version": "0.0.1", "description": "Capture a tab", "background_page" : "background.html", "browser_action": { "default_icon": "icon.png", "default_title": "Capture tab" }, "permissions" : ["tabs", "<all_urls>"] }
background.html:
<!DOCTYPE html> <html> <script type="text/javascript" src="background.js"></script> </html>
background.js:
chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.captureVisibleTab(null, function(img) { var xhr = new XMLHttpRequest(), formData = new FormData(); formData.append("img", img); xhr.open("POST", "http://myserver.com/submitImage", true); xhr.send(formData); }); });
This extension adds a browser button to Chrome. When the user clicks the button, the POST request containing the base64 encoded image (in the FormData object ) is sent to http://myserver.com/submitImage .
This code does not show how to manage server errors and response.
source share