From 06fa10b09cb95e56531c40a8afcc76a3ec19b42d Mon Sep 17 00:00:00 2001 From: Oj Date: Tue, 7 Feb 2023 13:12:21 +0000 Subject: [PATCH] launcher: finish allowRedirects --- src/launcher/inject.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/launcher/inject.js b/src/launcher/inject.js index 39a483a..5bcdf3d 100644 --- a/src/launcher/inject.js +++ b/src/launcher/inject.js @@ -42,18 +42,23 @@ export default async (CDP, proc, injectionType = 'browser', { dataPath, browserN 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; - if (allowRedirects === false && newUrl === url) return; + if (allowRedirects === true) return; // always allow redirects + if (allowRedirects === 'same-origin' && new URL(newUrl).origin === new URL(url).origin) return; // only allow if same origin + if (allowRedirects === false && newUrl === url) return; // only allow if identical open() url + if (newUrl === 'about:blank') return; // allow blank urls CDP.sendMessage('Page.stopLoading', {}, sessionId); if (msg.method === 'Page.frameNavigated') { - CDP.sendMessage('Page.navigate', { url: 'about:blank' }, sessionId); + // Page.frameNavigated will never be fired if we intercept the scheduled navigation + // but Firefox does not support that so this is a fallback + + // load about:blank whilst we do things + // CDP.sendMessage('Page.navigate', { url: 'about:blank' }, sessionId); const history = await CDP.sendMessage('Page.getNavigationHistory', {}, sessionId); let oldUrl = history.entries[history.currentIndex - 1].url; - if (oldUrl === 'about:blank') oldUrl = history.entries[history.currentIndex - 2].url; + // if (oldUrl === 'about:blank') oldUrl = history.entries[history.currentIndex - 2].url; CDP.sendMessage('Page.navigate', { url: oldUrl,