Skip to content

Commit e6fad8c

Browse files
committed
fix: add session check for extensions methods
1 parent 2212d0c commit e6fad8c

File tree

1 file changed

+15
-0
lines changed
  • packages/electron-chrome-extensions/src/browser

1 file changed

+15
-0
lines changed

packages/electron-chrome-extensions/src/browser/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export interface ChromeExtensionOptions extends ChromeExtensionImpl {
2828
*/
2929
license: License
3030

31+
/**
32+
* Session to add Chrome extension support in.
33+
* Defaults to `session.defaultSession`.
34+
*/
3135
session?: Electron.Session
3236

3337
/**
@@ -151,13 +155,23 @@ export class ElectronChromeExtensions extends EventEmitter {
151155
}
152156
}
153157

158+
private checkWebContentsArgument(wc: Electron.WebContents) {
159+
if (this.ctx.session !== wc.session) {
160+
throw new TypeError(
161+
'Invalid WebContents argument. Its session must match the session provided to ElectronChromeExtensions constructor options.',
162+
)
163+
}
164+
}
165+
154166
/** Add webContents to be tracked as a tab. */
155167
addTab(tab: Electron.WebContents, window: Electron.BaseWindow) {
168+
this.checkWebContentsArgument(tab)
156169
this.ctx.store.addTab(tab, window)
157170
}
158171

159172
/** Notify extension system that the active tab has changed. */
160173
selectTab(tab: Electron.WebContents) {
174+
this.checkWebContentsArgument(tab)
161175
if (this.ctx.store.tabs.has(tab)) {
162176
this.api.tabs.onActivated(tab.id)
163177
}
@@ -182,6 +196,7 @@ export class ElectronChromeExtensions extends EventEmitter {
182196
* @see https://developer.chrome.com/extensions/contextMenus
183197
*/
184198
getContextMenuItems(webContents: Electron.WebContents, params: Electron.ContextMenuParams) {
199+
this.checkWebContentsArgument(webContents)
185200
return this.api.contextMenus.buildMenuItemsForParams(webContents, params)
186201
}
187202

0 commit comments

Comments
 (0)