diff --git a/app/scripts/background.js b/app/scripts/background.js index c3b8a0c..e2a0e50 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -205,14 +205,14 @@ browser.runtime.onInstalled.addListener(function () { // create the offscreen document if it doesn't already exist async function createOffscreen() { - if (await chrome.offscreen.hasDocument?.()) return; - await chrome.offscreen.createDocument({ + if (await browser.offscreen === undefined || await browser.offscreen.hasDocument?.()) return; + await browser.offscreen.createDocument({ url: 'pages/offscreen.html', reasons: ['BLOBS'], justification: 'keep service worker running', }); } // a message from an offscreen document every 20 second resets the inactivity timer -chrome.runtime.onMessage.addListener((msg) => { +browser.runtime.onMessage.addListener((msg) => { if (msg.keepAlive) console.log('keepAlive'); }); diff --git a/app/scripts/offscreen.js b/app/scripts/offscreen.js index 92dce9d..70ceaba 100644 --- a/app/scripts/offscreen.js +++ b/app/scripts/offscreen.js @@ -1,4 +1,6 @@ +import * as browser from 'webextension-polyfill'; + // send a message every 20 sec to service worker setInterval(() => { - chrome.runtime.sendMessage({ keepAlive: true }); + browser.runtime.sendMessage({ keepAlive: true }); }, 20000);