-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
29 lines (26 loc) · 1.25 KB
/
Copy pathbackground.js
File metadata and controls
29 lines (26 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// // Background code is code that lives in the context of the browser
// returns visible tab as imageURL format
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === 'captureVisibleTab') {
chrome.tabs.captureVisibleTab(null, { format: 'png', quality: 100 }, dataUrl => {
sendResponse({ dataUrl: dataUrl });
});
return true; // To indicate that the response will be sent asynchronously
}
});
// sends action startScreenshotMode when pressing keybind defined in manifest.json
chrome.commands.onCommand.addListener(function(command) {
if (command === "startScreenshotModeShortcut") {
// Send a message to the content script to start the screenshot mode
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: "startScreenshotMode" });
});
}
});
// start screenshot mode when clicking on extension icon
chrome.browserAction.onClicked.addListener(function(tab) {
// alert("Extension icon clicked!");
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: "startScreenshotMode" });
});
});