aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background/backend.js
diff options
context:
space:
mode:
authorjbukl <noreply@github.com>2023-10-20 16:08:56 -0400
committerjbukl <noreply@github.com>2023-10-20 16:08:56 -0400
commit4c3f6f1a1714b575b18482080dbf4a235d5a1ad3 (patch)
treed993ad0367790bb1ac272580a6923e3fa0ec548d /ext/js/background/backend.js
parent9a39d0a7e2896edd4a6deebad00b8550cfffc15b (diff)
chore: cleanup offscreen documentation code
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r--ext/js/background/backend.js39
1 files changed, 17 insertions, 22 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 57565eec..abdf8271 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -2289,38 +2289,33 @@ class Backend {
// https://developer.chrome.com/docs/extensions/reference/offscreen/
async _setupOffscreenDocument() {
- // Check all windows controlled by the service worker to see if one
- // of them is the offscreen document with the given path
if (await this._hasOffscreenDocument()) {
return;
}
-
- // create offscreen document
if (this._creatingOffscreen) {
await this._creatingOffscreen;
- } else {
- this._creatingOffscreen = chrome.offscreen.createDocument({
- url: 'offscreen.html',
- reasons: ['CLIPBOARD'],
- justification: 'reason for needing the document'
- });
- await this._creatingOffscreen;
- this._creatingOffscreen = null;
+ return;
}
+
+ this._creatingOffscreen = chrome.offscreen.createDocument({
+ url: 'offscreen.html',
+ reasons: ['CLIPBOARD'],
+ justification: 'reason for needing the document'
+ });
+ await this._creatingOffscreen;
+ this._creatingOffscreen = null;
}
async _hasOffscreenDocument() {
const offscreenUrl = chrome.runtime.getURL('offscreen.html');
- if (chrome.runtime.getContexts) {
- const contexts = await chrome.runtime.getContexts({
- contextTypes: ['OFFSCREEN_DOCUMENT'],
- documentUrls: [offscreenUrl]
- });
- return Boolean(contexts.length);
- } else {
+ if (!chrome.runtime.getContexts) { // chrome version <116
const matchedClients = await clients.matchAll();
- return await matchedClients.some((client) => {
- client.url.includes(chrome.runtime.id);
- });
+ return !!(await matchedClients.some((client) => client.url === offscreenUrl));
}
+
+ const contexts = await chrome.runtime.getContexts({
+ contextTypes: ['OFFSCREEN_DOCUMENT'],
+ documentUrls: [offscreenUrl]
+ });
+ return !!contexts.length;
}
}