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?
preNavigationHooks: [
async ({ page, blockRequests }) => {
await page.setViewportSize({ width: 1920, height: 1080 })
await blockRequests({
urlPatterns: [".jpg", ".png", ".gif", ".svg"],
})
},
],
preNavigationHooks: [
async ({ page, blockRequests }) => {
await page.setViewportSize({ width: 1920, height: 1080 })
await blockRequests({
urlPatterns: [".jpg", ".png", ".gif", ".svg"],
})
},
],
1 Reply
broad-brown
broad-brown2y ago
Explained here: https://discord.com/channels/801163717915574323/1166025888765321337/1169366794268586087 You will probably need to use the request interception. E.g. page.on('request') for Pupppeteer and page.route for Playwright

Did you find this page helpful?