MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / setupOffscreenDocument

Function setupOffscreenDocument

src/service_worker.ts:29–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27}
28
29async function setupOffscreenDocument() {
30 if (typeof chrome.offscreen?.createDocument !== "function") {
31 // Firefox does not support offscreen
32 console.error("Your browser does not support chrome.offscreen.createDocument");
33 return;
34 }
35 //if we do not have a document, we are already setup and can skip
36 if (!(await hasDocument())) {
37 // create offscreen document
38 if (!creating) {
39 const promise = chrome.offscreen
40 .createDocument({
41 url: OFFSCREEN_DOCUMENT_PATH,
42 reasons: [
43 chrome.offscreen.Reason.BLOBS,
44 chrome.offscreen.Reason.CLIPBOARD,
45 chrome.offscreen.Reason.DOM_SCRAPING,
46 chrome.offscreen.Reason.LOCAL_STORAGE,
47 ],
48 justification: "offscreen page",
49 })
50 .then(() => {
51 if (creating !== promise) {
52 console.log("setupOffscreenDocument() calling is invalid.");
53 return;
54 }
55 creating = true; // chrome.offscreen.createDocument 只执行一次
56 });
57 creating = promise;
58 }
59 await creating;
60 }
61}
62
63function main() {
64 cleanInvalidKeys();

Callers 1

mainFunction · 0.85

Calls 3

hasDocumentFunction · 0.85
errorMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected