How to prevent following redirects to other domains?

I see there is a way to prevent this once page loads with something like this:
await page.setRequestInterception(true);

page.on('request', async (request) => {
if (ok) {
await request.continue();
} else {
await request.abort();
}
}
await page.setRequestInterception(true);

page.on('request', async (request) => {
if (ok) {
await request.continue();
} else {
await request.abort();
}
}
But how about when I have a url in queue, is there a nice way to have the request interception setup in the crawler options instead and have it defined globally?
3 Replies
equal-jade
equal-jadeOP•3y ago
I guess I'm looking for something like a global beforeNavigation callback. Yay, it's preNavigationHooks, I wasn't able to find it in the API docs though. Found it here in fulltext and then used github all code search for examples.
Pepa J
Pepa J•3y ago
Yes, you need to put this to the prenavigationHooks, did this solve your issue? 🙂
equal-jade
equal-jadeOP•3y ago
Yep I got it working, although I didn't end up blocking them in the end.

Did you find this page helpful?