feat: enable innerWidth and innerHeight for window open (#47039)

feat: enable innerWidth and innerHeight for window open (#46749)

* feat: enable innerWidth and innerHeight for window open

* update comment for added special innerWidth and innerHeight

* update 100 min spec requirement handling

* update testing to include getContentSize

* update macOS min requirement handling

* adjust refactored consts

* update const values from nativewindowviews

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Michaela Laurencin <35157522+mlaurencin@users.noreply.github.com>
This commit is contained in:
trop[bot]
2025-05-14 16:02:46 -05:00
committed by GitHub
parent ec83c1303c
commit bf54b8d709
6 changed files with 87 additions and 8 deletions

View File

@@ -1459,6 +1459,41 @@ describe('chromium features', () => {
expect(eventData).to.equal('size: 350 450');
});
it('window opened with innerWidth option has the same innerWidth', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const windowUrl = `file://${fixturesPath}/pages/window-open-size-inner.html`;
const windowCreatedPromise = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
const eventDataPromise = w.webContents.executeJavaScript(`(async () => {
const message = new Promise(resolve => window.addEventListener('message', resolve, { once: true }));
b = window.open(${JSON.stringify(windowUrl)}, '', 'show=no,innerWidth=400,height=450');
const e = await message;
b.close();
return e.data;
})()`);
const [[, newWindow], eventData] = await Promise.all([windowCreatedPromise, eventDataPromise]);
expect(newWindow.getContentSize().toString()).to.equal('400,450');
expect(eventData).to.equal('size: 400 450');
});
it('window opened with innerHeight option has the same innerHeight', async () => {
const w = new BrowserWindow({ show: false });
w.loadFile(path.resolve(__dirname, 'fixtures', 'blank.html'));
const windowUrl = `file://${fixturesPath}/pages/window-open-size-inner.html`;
const windowCreatedPromise = once(app, 'browser-window-created') as Promise<[any, BrowserWindow]>;
const eventDataPromise = w.webContents.executeJavaScript(`(async () => {
const message = new Promise(resolve => window.addEventListener('message', resolve, {once: true}));
const b = window.open(${JSON.stringify(windowUrl)}, '', 'show=no,width=350,innerHeight=400')
const e = await message;
b.close();
return e.data;
})()`);
const [[, newWindow], eventData] = await Promise.all([windowCreatedPromise, eventDataPromise]);
expect(newWindow.getContentSize().toString()).to.equal('350,400');
expect(eventData).to.equal('size: 350 400');
});
it('loads preload script after setting opener to null', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.setWindowOpenHandler(() => ({

View File

@@ -0,0 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
window.opener.postMessage('size: ' + innerWidth + ' ' + innerHeight, '*')
</script>
</body>
</html>