question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to page.setRequestInterception(true) if connecting to chrome

See original GitHub issue

For the browser instance puppeteer.launch it can do somethings like

await page.setRequestInterception(true);
page.on('request', request => {
    if (request.resourceType() === 'image') {
        request.abort();
    }
    else {
        request.continue();
    }
});

But it can not setRequestInterception(true) for a chrome instance ( I do puppeteer connect with chromelaucher or create a chrome with remote debug port manually)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jazoomcommented, Feb 24, 2019

So why exactly was this closed? The issue remains.

1reaction
jazoomcommented, Oct 26, 2018
  let browser;
  try {
    browser = await puppeteer.launch({
      headless: false,
      executablePath: 'chrome.exe',
      args: [`--proxy-server=${options.proxy.ip}:${options.proxy.port}`]
    });

    const page = await browser.newPage();
    await page.setViewport({ width: 800, height: 600 });

    await page.setRequestInterception(true);
    page.on('request', interceptedRequest => {
      console.log('YOU WILL NEVER SEE THIS LOGGED');
      if (['image', 'media', 'font', 'stylesheet'].includes(interceptedRequest.resourceType())) {
        return interceptedRequest.abort();
      }
      interceptedRequest.continue();
    });

    const response = await page.goto(options.url);

    const source = await response.text();

    const content = await page.content();

  } catch (error) {
  }

  browser && await browser.close();

@aslushnikov Since you’re already interpreting that code, can you see why response would be null? I got it from your comment here (https://github.com/GoogleChrome/puppeteer/issues/749#issuecomment-328600349). Unfortunately, response is always null so trying to get text() from it causes a TypeError.

Edit: I think response being null is related to the interception failure. The following is never logged:

    page.on('response', resp => {
      console.log('GOT A RESPONSE, YO');
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

how do POST request in puppeteer? - google chrome
I was having the issue that all of my page resources (scripts, CSS) were failing to load once I added POST data in...
Read more >
puppeteer-core@19.4.1 - jsDocs.io
A high-level API to control headless Chrome over the DevTools Protocol ... A Browser is created when Puppeteer connects to a Chromium ...
Read more >
Automation Protocols - WebdriverIO
If it can't find such driver it falls back to use Chrome DevTools using ... const page = (await puppeteer.pages())[0] ... setRequestInterception(true)
Read more >
Web Scraping with a Headless Browser: A Puppeteer Tutorial
The interceptor can be defined in the following way: await page.setRequestInterception(true); page.on('request', (request) => { ...
Read more >
Top 5 chrome-aws-lambda Code Examples - Snyk
newPage(); const nowTime = +new Date(); let reqCount = 0; await page.setRequestInterception(true); page.on('request', (request) => { const url ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found