fix(browser): handle Cmd-click popups without adopted WebContents (#8659)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
parent
81cc966ea3
commit
b379610cbe
|
|
@ -53,6 +53,11 @@ const { fakeElectron } = vi.hoisted(() => {
|
|||
webContents: FakeWebContents
|
||||
setBounds = vi.fn()
|
||||
constructor(options: { webContents?: FakeWebContents; webPreferences?: unknown }) {
|
||||
// Why: Electron rejects explicit undefined instead of treating it as
|
||||
// omitted, which the popup fallback path depends on.
|
||||
if (Object.hasOwn(options, 'webContents') && options.webContents === undefined) {
|
||||
throw new TypeError('options.webContents must be a WebContents')
|
||||
}
|
||||
this.options = options
|
||||
this.webContents = options.webContents ?? createFakeWebContents()
|
||||
FakeWebContentsView.instances.push(this)
|
||||
|
|
@ -186,6 +191,7 @@ describe('openPopupWithOriginBar', () => {
|
|||
|
||||
it('loads the target itself only when no pre-created contents were provided', () => {
|
||||
const popup = openPopupWithOriginBar({}, 'https://example.com/login')
|
||||
expect(lastViews().content.options).not.toHaveProperty('webContents')
|
||||
expect(popup.contentWebContents.loadURL).toHaveBeenCalledWith('https://example.com/login')
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,9 @@ export function openPopupWithOriginBar(
|
|||
webPreferences: { contextIsolation: true, nodeIntegration: false, sandbox: true }
|
||||
})
|
||||
const contentView = new WebContentsView({
|
||||
webContents: options.webContents,
|
||||
// Why: Electron rejects an explicitly undefined webContents; omitting it
|
||||
// lets WebContentsView create contents for Cmd/Ctrl-click popups.
|
||||
...(options.webContents === undefined ? {} : { webContents: options.webContents }),
|
||||
webPreferences: options.webPreferences
|
||||
})
|
||||
window.contentView.addChildView(contentView)
|
||||
|
|
|
|||
Loading…
Reference in New Issue