-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
39 lines (39 loc) · 1.07 KB
/
background.js
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
30
31
32
33
34
35
36
37
38
39
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log("hi");
if (message.action === "collectElements") {
(async () => {
const [tab] = await chrome.tabs.query({
active: true,
lastFocusedWindow: true,
});
console.log(message.query);
await chrome.tabs.sendMessage(tab.id, {
action: "collectElements",
query: message.query,
});
})();
} else if (message.action === "saveElements") {
(async () => {
const [tab] = await chrome.tabs.query({
active: true,
lastFocusedWindow: true,
});
await chrome.tabs.sendMessage(tab.id, {
action: "saveElements",
});
})();
} else if (message.action === "downloadBlob") {
// Use the chrome.downloads API to download the Blob URL
chrome.downloads
.download({
url: message.blobURL,
saveAs: true,
})
.then(() => {
chrome.tabs.sendMessage(sender.tab.id, {
action: "revokeBlob",
blobURL: message.blobURL,
});
});
}
});