()
| 27 | } |
| 28 | |
| 29 | async 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 | |
| 63 | function main() { |
| 64 | cleanInvalidKeys(); |
no test coverage detected