-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
45 lines (39 loc) · 1.18 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
40
41
42
43
44
45
// ServiceWorkerGlobalScope
addEventListener("install", async (e) => {
console.log(e.type);
e.waitUntil(self.skipWaiting());
});
addEventListener("activate", async (e) => {
console.log(e.type);
e.waitUntil(self.clients.claim());
});
addEventListener("fetch", async (e) => {
console.log(e.request.url, e.request.destination);
});
addEventListener("message", async (e) => {
console.log(e.data);
});
const bc = new BroadcastChannel("offscreen");
bc.addEventListener("message", async (e) => {
console.log(e.data);
if (e.data === "start") {
if (await chrome.offscreen.hasDocument()) {
await chrome.offscreen.closeDocument();
}
return await chrome.offscreen.createDocument({
url: "index.html",
reasons: ["TESTING"],
justification: "",
});
}
if (e.data === "reload") {
if (await chrome.offscreen.hasDocument()) {
await chrome.offscreen.closeDocument();
}
}
bc.postMessage(e.data);
});
chrome.runtime.onInstalled.addListener(async (reason) => {
await chrome.sidePanel.setOptions({ path: "controller.html", enabled: true });
await chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true }).catch(console.error);
});