mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: pass parsed features to setWindowOpenHandler() callback
This commit is contained in:
@@ -1174,6 +1174,7 @@ Ignore application menu shortcuts while this web contents is focused.
|
||||
* `url` string - The _resolved_ version of the URL passed to `window.open()`. e.g. opening a window with `window.open('foo')` will yield something like `https://the-origin/the/current/path/foo`.
|
||||
* `frameName` string - Name of the window provided in `window.open()`
|
||||
* `features` string - Comma separated list of window features provided to `window.open()`.
|
||||
* `parsedFeatures` Record<string, any> - Parsed version of the features.
|
||||
* `disposition` string - Can be `default`, `foreground-tab`, `background-tab`,
|
||||
`new-window`, `save-to-disk` or `other`.
|
||||
* `referrer` [Referrer](structures/referrer.md) - The referrer that will be
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { BrowserWindowConstructorOptions, LoadURLOptions } from 'electron/m
|
||||
import * as url from 'url';
|
||||
import * as path from 'path';
|
||||
import { openGuestWindow, makeWebPreferences, parseContentTypeFormat } from '@electron/internal/browser/guest-window-manager';
|
||||
import { parseFeatures } from '@electron/internal/browser/parse-features-string';
|
||||
import { parseFeatures, parseCommaSeparatedKeyValue } from '@electron/internal/browser/parse-features-string';
|
||||
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
|
||||
import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils';
|
||||
import { MessagePortMain } from '@electron/internal/browser/message-port-main';
|
||||
@@ -641,6 +641,7 @@ WebContents.prototype._init = function () {
|
||||
url,
|
||||
frameName,
|
||||
features: rawFeatures,
|
||||
parsedFeatures: parseCommaSeparatedKeyValue(rawFeatures),
|
||||
referrer,
|
||||
postBody,
|
||||
disposition
|
||||
@@ -680,6 +681,7 @@ WebContents.prototype._init = function () {
|
||||
url,
|
||||
frameName,
|
||||
features: rawFeatures,
|
||||
parsedFeatures: parseCommaSeparatedKeyValue(rawFeatures),
|
||||
disposition,
|
||||
referrer,
|
||||
postBody
|
||||
|
||||
@@ -197,7 +197,7 @@ describe('webContents.setWindowOpenHandler', () => {
|
||||
|
||||
it('fires handler with correct params', async () => {
|
||||
const testFrameName = 'test-frame-name';
|
||||
const testFeatures = 'top=10&left=10&something-unknown&show=no';
|
||||
const testFeatures = 'top=10,left=10,something-unknown,show=no';
|
||||
const testUrl = 'app://does-not-exist/';
|
||||
const details = await new Promise<Electron.HandlerDetails>(resolve => {
|
||||
browserWindow.webContents.setWindowOpenHandler((details) => {
|
||||
@@ -207,10 +207,16 @@ describe('webContents.setWindowOpenHandler', () => {
|
||||
|
||||
browserWindow.webContents.executeJavaScript(`window.open('${testUrl}', '${testFrameName}', '${testFeatures}') && true`);
|
||||
});
|
||||
const { url, frameName, features, disposition, referrer } = details;
|
||||
const { url, frameName, features, parsedFeatures, disposition, referrer } = details;
|
||||
expect(url).to.equal(testUrl);
|
||||
expect(frameName).to.equal(testFrameName);
|
||||
expect(features).to.equal(testFeatures);
|
||||
expect(parsedFeatures).to.deep.equal({
|
||||
left: 10,
|
||||
top: 10,
|
||||
'something-unknown': true,
|
||||
show: false
|
||||
});
|
||||
expect(disposition).to.equal('new-window');
|
||||
expect(referrer).to.deep.equal({
|
||||
policy: 'strict-origin-when-cross-origin',
|
||||
|
||||
Reference in New Issue
Block a user