Skip to content

Instantly share code, notes, and snippets.

@gduverger
Created February 6, 2021 17:06
Show Gist options
  • Save gduverger/e2952a6b8032d262fb792c749e6f6c5a to your computer and use it in GitHub Desktop.
Save gduverger/e2952a6b8032d262fb792c749e6f6c5a to your computer and use it in GitHub Desktop.
Dashcam (0.1)
chrome.runtime.onMessage.addListener((req, sender, res) => {
if (req.message === 'capture') {
// console.log('chrome.runtime.onMessage.addListener', req, sender, res);
chrome.tabs.captureVisibleTab(sender.tab.windowId, {format: 'png'}, (image) => {
// console.log('chrome.tabs.captureVisibleTab', image); // image is base64
res({image: image});
});
}
return true;
});
// alert('content');
chrome.runtime.sendMessage({message: 'capture'}, (res) => {
// alert('chrome.runtime.sendMessage');
var link = document.createElement('a');
link.download = 'screenshot.png';
link.href = res.image;
link.click();
});
{
"manifest_version": 2,
"name": "Dashcam",
"version": "0.1",
"permissions": ["<all_urls>"],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment