diff --git a/packages/electron-chrome-extensions/src/browser-action.ts b/packages/electron-chrome-extensions/src/browser-action.ts index d06b6fc..935841a 100644 --- a/packages/electron-chrome-extensions/src/browser-action.ts +++ b/packages/electron-chrome-extensions/src/browser-action.ts @@ -405,8 +405,8 @@ export const injectBrowserAction = () => { contextBridge.exposeInMainWorld('browserAction', __browserAction__) // Must execute script in main world to modify custom component registry. - ;(contextBridge as any).evaluateInMainWorld({ - func: mainWorldScript + ;(contextBridge as any).executeInMainWorld({ + func: mainWorldScript, }) } else { // When contextIsolation is disabled, contextBridge will throw an error. diff --git a/packages/electron-chrome-extensions/src/browser/router.ts b/packages/electron-chrome-extensions/src/browser/router.ts index e2eac61..5c73284 100644 --- a/packages/electron-chrome-extensions/src/browser/router.ts +++ b/packages/electron-chrome-extensions/src/browser/router.ts @@ -21,7 +21,7 @@ const getSessionFromEvent = (event: any): Electron.Session => { // TODO(mv3): add types const getHostFromEvent = (event: any) => { if (event.type === 'service-worker') { - const serviceWorker = event.session.serviceWorkers.fromVersionID(event.versionId) + const serviceWorker = event.session.serviceWorkers.getWorkerFromVersionID(event.versionId) return serviceWorker && !serviceWorker.isDestroyed() ? serviceWorker : null } else { return event.sender @@ -72,7 +72,9 @@ class RoutingDelegate { const maybeListenForWorkerEvents = ({ runningStatus, versionId }: any) => { if (runningStatus !== 'starting') return - const serviceWorker = (observer.session as any).serviceWorkers.fromVersionID(versionId) + const serviceWorker = (observer.session as any).serviceWorkers.getWorkerFromVersionID( + versionId, + ) if ( serviceWorker?.scope?.startsWith('chrome-extension://') && !this.workers.has(serviceWorker) @@ -209,15 +211,18 @@ export class ExtensionRouter { } }) - session.serviceWorkers.on('running-status-changed' as any, ({ runningStatus, versionId }: any) => { - if (runningStatus !== 'starting') return + session.serviceWorkers.on( + 'running-status-changed' as any, + ({ runningStatus, versionId }: any) => { + if (runningStatus !== 'starting') return - const serviceWorker = (session as any).serviceWorkers.fromVersionID(versionId) - if (serviceWorker) { - debug(`storing reference to background service worker [url:'${serviceWorker.scope}']`) - this.extensionWorkers.add(serviceWorker) - } - }) + const serviceWorker = (session as any).serviceWorkers.getWorkerFromVersionID(versionId) + if (serviceWorker) { + debug(`storing reference to background service worker [url:'${serviceWorker.scope}']`) + this.extensionWorkers.add(serviceWorker) + } + }, + ) } private filterListeners(predicate: (listener: EventListener) => boolean) { @@ -380,7 +385,9 @@ export class ExtensionRouter { if (host.constructor.name === 'ServiceWorkerMain') { if (host.isDestroyed()) { - console.error(`Service Worker is destroyed.\nUnable to send '${eventName}' to extension host for ${extensionId}`) + console.error( + `Service Worker is destroyed.\nUnable to send '${eventName}' to extension host for ${extensionId}`, + ) return } host.startWorker().then(send) diff --git a/packages/electron-chrome-extensions/src/renderer/index.ts b/packages/electron-chrome-extensions/src/renderer/index.ts index af763f5..d406a86 100644 --- a/packages/electron-chrome-extensions/src/renderer/index.ts +++ b/packages/electron-chrome-extensions/src/renderer/index.ts @@ -158,7 +158,7 @@ export const injectExtensionAPIs = () => { if (manifest.manifest_version === 3) { // TODO(mv3): might need to use offscreen document to serialize console.warn( - 'action.setIcon with imageData is not yet supported by electron-chrome-extensions' + 'action.setIcon with imageData is not yet supported by electron-chrome-extensions', ) details.imageData = undefined } else if (details.imageData instanceof ImageData) { @@ -169,7 +169,7 @@ export const injectExtensionAPIs = () => { obj[pair[0]] = imageData2base64(pair[1]) return obj }, - {} + {}, ) } } @@ -314,11 +314,11 @@ export const injectExtensionAPIs = () => { ...base, isAllowedFileSchemeAccess: invokeExtension('extension.isAllowedFileSchemeAccess', { noop: true, - defaultResponse: false + defaultResponse: false, }), isAllowedIncognitoAccess: invokeExtension('extension.isAllowedIncognitoAccess', { noop: true, - defaultResponse: false + defaultResponse: false, }), // TODO: Add native implementation getViews: () => [], @@ -415,7 +415,11 @@ export const injectExtensionAPIs = () => { const api = { ...base, create: invokeExtension('tabs.create'), - executeScript: async function (arg1: unknown, arg2: unknown, arg3: unknown): Promise { + executeScript: async function ( + arg1: unknown, + arg2: unknown, + arg3: unknown, + ): Promise { // Electron's implementation of chrome.tabs.executeScript is in // C++, but it doesn't support implicit execution in the active // tab. To handle this, we need to get the active tab ID and @@ -541,8 +545,8 @@ export const injectExtensionAPIs = () => { contextBridge.exposeInMainWorld('electron', electronContext) // Mutate global 'chrome' object with additional APIs in the main world. - ;(contextBridge as any).evaluateInMainWorld({ - func: mainWorldScript + ;(contextBridge as any).executeInMainWorld({ + func: mainWorldScript, }) } catch (error) { console.error(`injectExtensionAPIs error (${location.href})`)