NeoNomade | Scraping hellhound
04/23/2025, 10:32 AMtypescript
preNavigationHooks: [
async (gotoOptions) => {
gotoOptions.waitUntil = "load";
},
async ({page}) => {
await page.route("**/*", async (route) => {
const url = route.request().url();
const resourceType = route.request().resourceType();
const trackingScriptRegex =
/googletagmanager|facebook|sentry|ads|tracking|metrics|analytics|optimizely|segment/i;
const extraBlocklistRegex =
/tiktok|facebook|prismic-images|bing|ads|tracking|metrics|analytics|contentsquare|lytics|adtrafficquality|adsrvr|tmol|snapchat|ticketm\.net/i;
const isBlockedResourceType = ["stylesheet", "font", "media"].includes(resourceType);
const isBlockedScript = resourceType === "script" && trackingScriptRegex.test(url);
const isBlockedByExtraPatterns = extraBlocklistRegex.test(url);
const shouldBlock =
!url.includes("recaptcha") &&
(isBlockedResourceType || isBlockedScript || isBlockedByExtraPatterns);
if (shouldBlock) {
await route.abort();
return;
}
await route.continue();
});
},
],Hall
04/23/2025, 10:32 AMNeoNomade | Scraping hellhound
04/23/2025, 11:37 AMolexandra_59608
04/23/2025, 12:04 PMlog.info() or console.log() in your code, so I don't know what particularly you are trying to log. I tested logging locally with fresh Crawlee + Playwright + Camoufox JS template, and it worked for me. Here is a snippet:
preNavigationHooks: [
async ({ page, log }) => {
try {
log.info('Log before route.);
await page.route('https://apify.com/', async (route) => {
log.info('Log from inside.');
await route.continue();
});
} catch (error) {
log.error('Error log from outside.');
}
},
],
Can you, please, be more specific about what you're trying to print?NeoNomade | Scraping hellhound
04/23/2025, 12:07 PMtypescript
const abortAssets: PlaywrightHook = async ({ page }) => {
const RESOURCE_EXCLUSIONS = ['image', 'media', 'font', 'stylesheet'];
console.log('Welcome to AbortAssets')
await page.route('**/*', (route) => {
console.log(route.request().url)
if (RESOURCE_EXCLUSIONS.includes(route.request().resourceType())) {
return route.abort();
}
return route.continue();
});
};
the Welcome to AbortAssets log I see.
the next one I don't.
I can't figure out where is this bug coming from.
I've replaced crawlee's internal logger with Pino.
And I was using opentelemetry to get some host analytics.
Disabled opentelemetry SDK, and still the routes are not working...NeoNomade | Scraping hellhound
04/23/2025, 12:49 PMNeoNomade | Scraping hellhound
04/23/2025, 12:59 PMolexandra_59608
04/23/2025, 7:55 PMpage.goto() is not handled identically to regular request navigation. If you do need to get to this page again with preNavigationHooks being triggered, consider adding request to requestQueue with uniqueKey and additional data, that will prevent you from getting 401 again. Hope it helps.NeoNomade | Scraping hellhound
04/24/2025, 1:40 PMapify_matymar
04/28/2025, 1:01 PMNeoNomade | Scraping hellhound
04/28/2025, 1:01 PMNeoNomade | Scraping hellhound
04/28/2025, 1:02 PMapify_matymar
04/28/2025, 1:03 PM