change package name from launch-browser-with-preload-extension to launch-bosszhipin-login-page-with-preload-extension

This commit is contained in:
geekgeekrun
2024-03-01 23:45:14 +08:00
parent d0c8dc0410
commit 7f2e241773
6 changed files with 60 additions and 127 deletions
@@ -0,0 +1,25 @@
export async function blockNavigation(page, predictor = (url) => true) {
console.log(`block navigation for puppeteer page from url ${page.url()}`)
await page.setRequestInterception(true)
const handler = (req) => {
if (req.isNavigationRequest() && req.frame() === page.mainFrame() && predictor(req)) {
req.abort('aborted')
} else {
try {
req.continue()
} catch {
//
}
}
}
page.on('request', handler)
return {
dispose: async () => {
page.off('request', handler)
await page.setRequestInterception(false)
}
}
}