Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/electron-chrome-extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'
Expand Down
11 changes: 10 additions & 1 deletion packages/electron-chrome-extensions/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Electron.Session, ElectronChromeExtensions>()
Expand Down Expand Up @@ -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)
}
}
Expand Down