setRequestInterception method

Future<void> setRequestInterception(
  1. bool value
)

Whether to enable request interception.

Activating request interception enables request.abort, request.continue and request.respond methods. This provides the capability to modify network requests that are made by a page.

Once request interception is enabled, every request will stall unless it's continued, responded or aborted. An example of a naïve request interceptor that aborts all image requests:

var browser = await puppeteer.launch();
var page = await browser.newPage();
await page.setRequestInterception(true);
page.onRequest.listen((interceptedRequest) {
  if (interceptedRequest.url.endsWith('.png') ||
      interceptedRequest.url.endsWith('.jpg')) {
    interceptedRequest.abort();
  } else {
    interceptedRequest.continueRequest();
  }
});
await page.goto('https://example.com');
await browser.close();

NOTE Enabling request interception disables page caching.

Implementation

Future<void> setRequestInterception(bool value) {
  return _frameManager.networkManager.setRequestInterception(value);
}