1

I recently tried to intercept all image requests following the example in their documentation:

await page.route('**/*.{png,jpg,jpeg}', route => route.abort());

// Abort based on the request type
await page.route('**/*', route => {
  return route.request().resourceType() === 'image' ?
      route.abort() : route.continue();
});

But it was not working at all.

How can I make it work?

Soldeplata Saketos
  • 3,212
  • 1
  • 25
  • 38

1 Answers1

1

There is a missing string in the types (or they are outdated in v1.15.1):enter image description here

When logging route.request().resourceType() into console, I noticed there is a "images" resource type. So you can easily intercept any images including "images" to your check.

For instance you could do like this:

await page.route('**/*', route => {
  return route.request().resourceType().match(/(image)s?/) ?
      route.abort() : route.continue();
});
Soldeplata Saketos
  • 3,212
  • 1
  • 25
  • 38