diff --git a/packages/electron-chrome-extensions/README.md b/packages/electron-chrome-extensions/README.md index 3df36325..2fb9f8b8 100644 --- a/packages/electron-chrome-extensions/README.md +++ b/packages/electron-chrome-extensions/README.md @@ -20,6 +20,9 @@ npm install electron-chrome-extensions ## Usage +> [!IMPORTANT] +> You must initialize the `ElectronChromeExtensions` class before installing any extensions, otherwise it might not work as expected. + ### Basic Simple browser using Electron's [default session](https://www.electronjs.org/docs/api/session#sessiondefaultsession) and one tab. @@ -134,6 +137,7 @@ module.exports = { Valid options include `GPL-3.0`, `Patron-License-2020-11-19` - `session` Electron.Session (optional) - Session which should support Chrome extension APIs. `session.defaultSession` is used by default. + - `registerCrxProtocolInDefaultSession` Boolean (optional) - Whether to register the 'crx://' protocol in the default session. Defaults to `true`. - `createTab(details) => Promise<[Electron.WebContents, Electron.BrowserWindow]>` (optional) - Called when `chrome.tabs.create` is invoked by an extension. Allows the application to handle how tabs are created. @@ -211,6 +215,14 @@ Example: } ``` +##### `extensions.handleCrxRequest(request)` + +- `request` GlobalRequest + +Handle a request to the 'crx://' protocol. + +Returns `GlobalResponse` + #### Instance Events ##### Event: 'browser-action-popup-created' diff --git a/packages/electron-chrome-extensions/src/browser/index.ts b/packages/electron-chrome-extensions/src/browser/index.ts index d2e60c6b..8a14b1be 100644 --- a/packages/electron-chrome-extensions/src/browser/index.ts +++ b/packages/electron-chrome-extensions/src/browser/index.ts @@ -74,6 +74,12 @@ export interface ChromeExtensionOptions extends ChromeExtensionImpl { * @deprecated See "Packaging the preload script" in the readme. */ modulePath?: string + + /** + * Whether to register the 'crx://' protocol in the default session. + * Defaults to `true`. + */ + registerCrxProtocolInDefaultSession?: boolean } const sessionMap = new WeakMap() @@ -143,7 +149,10 @@ export class ElectronChromeExtensions extends EventEmitter { this.prependPreload(opts.modulePath) // Register crx:// protocol in default session for convenience - if (this.ctx.session !== electronSession.defaultSession) { + if ( + opts.registerCrxProtocolInDefaultSession !== false && + this.ctx.session !== electronSession.defaultSession + ) { this.handleCRXProtocol(electronSession.defaultSession) } }