launcher: add allowRedirects option (wip)
This commit is contained in:
parent
20dd0a9e4d
commit
98c4199fe0
@ -185,7 +185,7 @@ const getBrowserType = name => { // todo: not need this
|
||||
const portRange = [ 10000, 60000 ];
|
||||
const generatePort = () => (Math.floor(Math.random() * (portRange[1] - portRange[0] + 1)) + portRange[0]);
|
||||
|
||||
const startBrowser = async (url, { allowHTTP, windowSize, forceBrowser, forceEngine }) => {
|
||||
const startBrowser = async (url, { allowHTTP = false, allowRedirects = 'same-origin', windowSize, forceBrowser, forceEngine }) => {
|
||||
const [ browserPath, browserName ] = await findBrowserPath(forceBrowser, forceEngine);
|
||||
const browserFriendlyName = getFriendlyName(browserName);
|
||||
|
||||
@ -219,14 +219,15 @@ const startBrowser = async (url, { allowHTTP, windowSize, forceBrowser, forceEng
|
||||
openingLocal,
|
||||
closeHandlers,
|
||||
browserType,
|
||||
dataPath
|
||||
dataPath,
|
||||
allowRedirects
|
||||
});
|
||||
|
||||
return Window;
|
||||
};
|
||||
|
||||
export const open = async (url, opts = {}) => {
|
||||
const { onLoad, allowHTTP } = opts;
|
||||
const { onLoad, allowHTTP = false } = opts;
|
||||
|
||||
if (allowHTTP !== true && url.startsWith('http://')) throw new Error(`HTTP URLs are blocked by default. Please use HTTPS, or if not possible, enable the 'allowHTTP' option.`);
|
||||
|
||||
|
@ -27,7 +27,7 @@ const acquireTarget = async (CDP, filter = () => true) => {
|
||||
})).sessionId;
|
||||
};
|
||||
|
||||
export default async (CDP, proc, injectionType = 'browser', { dataPath, browserName, browserType, openingLocal, localUrl, url, closeHandlers }) => {
|
||||
export default async (CDP, proc, injectionType = 'browser', { dataPath, browserName, browserType, openingLocal, localUrl, url, allowRedirects, closeHandlers }) => {
|
||||
let pageLoadCallback, pageLoadPromise = new Promise(res => pageLoadCallback = res);
|
||||
let frameLoadCallback = () => {}, onWindowMessage = () => {};
|
||||
CDP.onMessage(msg => {
|
||||
@ -39,6 +39,20 @@ export default async (CDP, proc, injectionType = 'browser', { dataPath, browserN
|
||||
injectIPC(); // ensure IPC injection again
|
||||
} catch { }
|
||||
}
|
||||
|
||||
if (msg.method === 'Page.frameScheduledNavigation' || msg.method === 'Page.frameNavigated') {
|
||||
let newUrl = msg.params?.frame?.url ?? msg.params?.url;
|
||||
if (allowRedirects === true) return;
|
||||
if (allowRedirects === 'same-origin' && new URL(newUrl).origin === new URL(url).origin) return;
|
||||
|
||||
CDP.sendMessage('Page.stopLoading', {}, sessionId);
|
||||
|
||||
if (msg.method === 'Page.frameNavigated') {
|
||||
CDP.sendMessage('Page.navigate', { url: 'about:blank' }, sessionId);
|
||||
// CDP.sendMessage('Page.navigate')
|
||||
}
|
||||
// CDP.sendMessage('Page.navigate', { url: 'about:blank' }, sessionId);
|
||||
}
|
||||
});
|
||||
|
||||
// when the process has exited (all windows closed), clean up window internally
|
||||
|
Loading…
x
Reference in New Issue
Block a user