mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-04 20:38:03 +00:00
parent
37769e463c
commit
8b34c6d12d
@ -235,6 +235,46 @@ describe('onNewWindowHelper', () => {
|
||||
expect(mockOpenExternal).not.toHaveBeenCalled();
|
||||
expect(preventDefault).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('about:blank#blocked urls should be handled', () => {
|
||||
const options = {
|
||||
blockExternalUrls: false,
|
||||
targetUrl: originalURL,
|
||||
};
|
||||
onNewWindowHelper(
|
||||
options,
|
||||
setupWindow,
|
||||
'about:blank#blocked',
|
||||
undefined,
|
||||
preventDefault,
|
||||
);
|
||||
|
||||
expect(mockCreateAboutBlank).toHaveBeenCalledTimes(1);
|
||||
expect(mockCreateNewTab).not.toHaveBeenCalled();
|
||||
expect(mockBlockExternalURL).not.toHaveBeenCalled();
|
||||
expect(mockOpenExternal).not.toHaveBeenCalled();
|
||||
expect(preventDefault).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('about:blank#other urls should not be handled', () => {
|
||||
const options = {
|
||||
blockExternalUrls: false,
|
||||
targetUrl: originalURL,
|
||||
};
|
||||
onNewWindowHelper(
|
||||
options,
|
||||
setupWindow,
|
||||
'about:blank#other',
|
||||
undefined,
|
||||
preventDefault,
|
||||
);
|
||||
|
||||
expect(mockCreateAboutBlank).not.toHaveBeenCalled();
|
||||
expect(mockCreateNewTab).not.toHaveBeenCalled();
|
||||
expect(mockBlockExternalURL).not.toHaveBeenCalled();
|
||||
expect(mockOpenExternal).not.toHaveBeenCalled();
|
||||
expect(preventDefault).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onWillNavigate', () => {
|
||||
|
@ -40,6 +40,7 @@ export function onNewWindow(
|
||||
parent,
|
||||
});
|
||||
const preventDefault = (newGuest: BrowserWindow): void => {
|
||||
log.debug('onNewWindow.preventDefault', { newGuest, event });
|
||||
event.preventDefault();
|
||||
if (newGuest) {
|
||||
event.newGuest = newGuest;
|
||||
@ -77,29 +78,28 @@ export function onNewWindowHelper(
|
||||
} else {
|
||||
return openExternal(urlToGo);
|
||||
}
|
||||
} else if (urlToGo === 'about:blank') {
|
||||
const newWindow = createAboutBlankWindow(options, setupWindow, parent);
|
||||
return Promise.resolve(preventDefault(newWindow));
|
||||
}
|
||||
// Normally the following would be:
|
||||
// if (urlToGo.startsWith('about:blank'))...
|
||||
// But due to a bug we resolved in https://github.com/nativefier/nativefier/issues/1197
|
||||
// Some sites use about:blank#something to use as placeholder windows to fill
|
||||
// with content via JavaScript. So we'll stay specific for now...
|
||||
else if (['about:blank', 'about:blank#blocked'].includes(urlToGo)) {
|
||||
return Promise.resolve(
|
||||
preventDefault(createAboutBlankWindow(options, setupWindow, parent)),
|
||||
);
|
||||
} else if (nativeTabsSupported()) {
|
||||
if (disposition === 'background-tab') {
|
||||
const newTab = createNewTab(
|
||||
options,
|
||||
setupWindow,
|
||||
urlToGo,
|
||||
false,
|
||||
parent,
|
||||
);
|
||||
return Promise.resolve(preventDefault(newTab));
|
||||
} else if (disposition === 'foreground-tab') {
|
||||
const newTab = createNewTab(
|
||||
options,
|
||||
setupWindow,
|
||||
urlToGo,
|
||||
true,
|
||||
parent,
|
||||
);
|
||||
return Promise.resolve(preventDefault(newTab));
|
||||
}
|
||||
return Promise.resolve(
|
||||
preventDefault(
|
||||
createNewTab(
|
||||
options,
|
||||
setupWindow,
|
||||
urlToGo,
|
||||
disposition === 'foreground-tab',
|
||||
parent,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
} catch (err: unknown) {
|
||||
@ -168,13 +168,13 @@ export function setupNativefierWindow(options, window: BrowserWindow): void {
|
||||
sendParamsOnDidFinishLoad(options, window);
|
||||
|
||||
// @ts-expect-error new-tab isn't in the type definition, but it does exist
|
||||
window.on('new-tab', () =>
|
||||
window.on('new-tab', () => {
|
||||
createNewTab(
|
||||
options,
|
||||
setupNativefierWindow,
|
||||
options.targetUrl,
|
||||
true,
|
||||
window,
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user