Apify and Crawlee Official Forum

Updated 4 months ago

Blocking requests after click

I am using preNavigationHooks to block images, which works for the initial page load but does not block images loaded after a click on the page (i.e. XHR requests). How can these be blocked?

Plain Text
preNavigationHooks: [
    async ({ page, blockRequests }) => {
        await page.setViewportSize({ width: 1920, height: 1080 })
        await blockRequests({
            urlPatterns: [".jpg", ".png", ".gif", ".svg"],
        })
    },
],
L
2 comments
You will probably need to use the request interception. E.g. page.on('request') for Pupppeteer and page.route for Playwright
Add a reply
Sign up and join the conversation on Discord