Skip to content

Commit

Permalink
fix: remove window browser polyfill from ext background
Browse files Browse the repository at this point in the history
  • Loading branch information
peronczyk committed Jun 18, 2024
1 parent ec19ba4 commit 0181251
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import '@/lib/initPolyfills';
import { PopupActionType } from '@/types';
import { openPopup, removePopup, getPopup } from './bgPopupHandler';
import { updateDynamicRules } from './redirectRule';

async function setupOffscreenDocument(path: string) {
(async () => {
// Check all windows controlled by the service worker to see if one
// of them is the offscreen document with the given path
const offscreenUrl = browser.runtime.getURL(path);
const offscreenUrl = browser.runtime.getURL('offscreen.html');

// @ts-expect-error - browser type is not complete
const existingContexts = await browser.runtime.getContexts({
contextTypes: ['OFFSCREEN_DOCUMENT'],
Expand All @@ -19,13 +19,11 @@ async function setupOffscreenDocument(path: string) {

// @ts-expect-error - browser type is not complete
await browser.offscreen.createDocument({
url: path,
url: offscreenUrl,
reasons: ['LOCAL_STORAGE'],
justification: 'handle wallet-aepp communication',
});
}

setupOffscreenDocument(browser.runtime.getURL('offscreen.html'));
})();

export type PopupMessageData = {
target?: 'background' | 'offscreen';
Expand All @@ -37,7 +35,7 @@ export type PopupMessageData = {
};

/**
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage#sending_an_asynchronous_response_using_sendresponse
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage#sending_an_asynchronous_response_using_sendresponse
*/
function handleMessage(msg: PopupMessageData, _: any, sendResponse: Function) {
if (msg.target === 'background') {
Expand Down

0 comments on commit 0181251

Please sign in to comment.