mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
fix: offscreen mode under window.open creation (#47868)
fix: offscreen mode under new window creation
This commit is contained in:
@@ -4,6 +4,7 @@ import { expect, assert } from 'chai';
|
||||
|
||||
import { once } from 'node:events';
|
||||
import * as http from 'node:http';
|
||||
import * as nodePath from 'node:path';
|
||||
|
||||
import { HexColors, ScreenCapture, hasCapturableScreen } from './lib/screen-helpers';
|
||||
import { ifit, listen } from './lib/spec-helpers';
|
||||
@@ -203,6 +204,66 @@ describe('webContents.setWindowOpenHandler', () => {
|
||||
expect(await browserWindow.webContents.executeJavaScript('42')).to.equal(42);
|
||||
});
|
||||
|
||||
it('can open an offscreen child window from an onscreen parent', async () => {
|
||||
browserWindow.webContents.setWindowOpenHandler(() => ({
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
const didCreateWindow = once(browserWindow.webContents, 'did-create-window');
|
||||
const url = `file://${nodePath.join('fixtures', 'pages', 'content.html')}`;
|
||||
browserWindow.webContents.executeJavaScript(`window.open('${JSON.stringify(url)}') && true`);
|
||||
const [childWindow] = await didCreateWindow;
|
||||
expect(childWindow.webContents.isOffscreen()).to.be.true('Child window should be offscreen');
|
||||
});
|
||||
|
||||
it('can open an onscreen child window from an offscreen parent', async () => {
|
||||
const obw = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
});
|
||||
|
||||
await obw.loadURL('about:blank');
|
||||
obw.webContents.setWindowOpenHandler(() => ({ action: 'allow' }));
|
||||
|
||||
const didCreateWindow = once(obw.webContents, 'did-create-window');
|
||||
const url = `file://${nodePath.join('fixtures', 'pages', 'content.html')}`;
|
||||
obw.webContents.executeJavaScript(`window.open('${JSON.stringify(url)}') && true`);
|
||||
const [childWindow] = await didCreateWindow;
|
||||
expect(childWindow.webContents.isOffscreen()).to.be.false('Child window should not be offscreen');
|
||||
});
|
||||
|
||||
it('can open an offscreen child window from an offscreen parent', async () => {
|
||||
const obw = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
});
|
||||
|
||||
await obw.loadURL('about:blank');
|
||||
obw.webContents.setWindowOpenHandler(() => ({
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: {
|
||||
offscreen: true
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
const didCreateWindow = once(obw.webContents, 'did-create-window');
|
||||
const url = `file://${nodePath.join('fixtures', 'pages', 'content.html')}`;
|
||||
obw.webContents.executeJavaScript(`window.open('${JSON.stringify(url)}') && true`);
|
||||
const [childWindow] = await didCreateWindow;
|
||||
expect(childWindow.webContents.isOffscreen()).to.be.true('Child window should be offscreen');
|
||||
});
|
||||
|
||||
ifit(hasCapturableScreen())('should not make child window background transparent', async () => {
|
||||
browserWindow.webContents.setWindowOpenHandler(() => ({ action: 'allow' }));
|
||||
const didCreateWindow = once(browserWindow.webContents, 'did-create-window');
|
||||
|
||||
Reference in New Issue
Block a user