Skip to content

Commit

Permalink
fix: worker does not setup correctly (#11288)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Jan 15, 2024
1 parent 9a95409 commit 161e1eb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
11 changes: 0 additions & 11 deletions packages/mask/public/js/trusted-types.js

This file was deleted.

10 changes: 5 additions & 5 deletions packages/mask/public/manifest-v3.entry.js
@@ -1,11 +1,11 @@
// this file must be in the root due to limitation of mv3 service worker.
try {
importScripts(
'./worker.js',
'./js/gun.js',
'./js/polyfill/browser-polyfill.js',
'./sandboxed-modules/mv3-preload.js',
'./entry/backgroundWorker.js',
'/worker.js',
'/js/gun.js',
'/js/polyfill/browser-polyfill.js',
'/sandboxed-modules/mv3-preload.js',
'/entry/backgroundWorker.js',
)
} catch (error) {
// Note: this try catch is for Safari. If Safari extension failed to initialize, we cannot see the error message without this try-catch.
Expand Down
11 changes: 5 additions & 6 deletions packages/mask/public/worker.js
@@ -1,8 +1,7 @@
importScripts(
'./js/patches.js',
'./js/polyfill/ecmascript.js',
'./js/polyfill/lockdown.js',
'./js/lockdown.js',
'./js/trusted-types.js',
'./js/module-loader.js',
'/js/patches.js',
'/js/polyfill/ecmascript.js',
'/js/polyfill/lockdown.js',
'/js/lockdown.js',
'/js/module-loader.js',
)
11 changes: 11 additions & 0 deletions packages/mask/web-workers/prepare.ts
@@ -1,3 +1,14 @@
/// <reference path="../../polyfills/types/dom.d.ts" />
if (typeof trustedTypes === 'object' && location.protocol.includes('extension')) {
trustedTypes.createPolicy('default', {
// do not add createHTML or createScript.
// createScriptURL is safe because according to the CSP we have, it is impossible to
// include/create a script from cross-origin.
createScriptURL: (string) => string,
})
}

importScripts('/worker.js')
if (typeof self !== 'undefined') {
/**
* Workaround: Webpack child compiler doesn't inherit plugins but inherit loaders.
Expand Down

0 comments on commit 161e1eb

Please sign in to comment.