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.

Intercept Requests Event is Broken

See original GitHub issue

Steps to reproduce

This works in 1.6.2 at least, does not work in any other version I have tried after *1.12, 1.13 etc…

Tell us about your environment:

  • Puppeteer version: 1.12 or anything above 1.6.2 it seems
  • Platform / OS version: WINDOWS 10
  • URLs (if applicable): www.google.com
  • Node.js version: latest

What steps will reproduce the problem? Enable Intercept Request Load page all resources are now pending.

Please include code that reproduces the issue.

 const browser = await launch({
    headless: false,
    args: [
      // `--proxy-server=${ROUTER_PROXY}`,
      "--no-sandbox",
      "--disable-setuid-sandbox",
      "--disable-dev-shm-usage",
      "--disable-accelerated-2d-canvas",
      "--disable-gpu",
      "--window-size=1920x1080",
      "--enable-feature=NetworkService"
    ]
  });
private interceptRequest = async (request: puppeteer.Request) => {
    console.warn("INTERCEPTED");
    await request.continue();
    return;
}

 const page = await browser.newPage();
      page.on("request", this.interceptRequest);

      this.page = page;
      await page.setViewport({ width: 1920, height: 1080 });
      await page.setUserAgent(this.agent);
      await page.setRequestInterception(true);
      page.on("response", this.interceptResponse);
      this.logger("Request Interception On");

      await page.goto("http://www.google.com");

What is the expected result? For the page to load correctly

image

What happens instead? Currently it loads the page without any other asset (images, fonts )

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Morphexecommented, Mar 5, 2019

@aslushnikov So I found out its a scoping issue, the “this” is being rebinded by puppeter or something else on its inner workings. Thats why it wasn’t working, although I am not sure why the requests were being hanged even with that. But I figured it out by using lambdas, so should be fine for now.

What threw me off was that the old version was working perfectly, I was looking at examples and it was the same thing as before, so I couldn’t figure out what was running through on this.

1reaction
aslushnikovcommented, Mar 5, 2019

@Morphexe the following works just fine for me on v1.13.0:

const puppeteer = require('puppeteer');

async function main() {
    const browser = await puppeteer.launch({headless: false})
    const page = await browser.newPage()
    await page.setRequestInterception(true);
    page.on('request', request => {
      console.log('INTERCEPTED: ' + request.url());
      request.continue();
    });
    await page.goto('https://google.com');
}
main()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Intercept HTTP requests - Mozilla - MDN Web Docs
To intercept HTTP requests, use the webRequest API. ... The logURL() function grabs the URL of the request from the event object and...
Read more >
Why is intercepting requests in the pyppeteer not working?
No matter where I go, I don't get a single request loaded. Everything works without intercepting requests. What could be the problem? python ......
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
The command cy.intercept can match requests using a substring, ... Use specific intercepts and make sure the stubs are not "breaking" any ...
Read more >
Intercepting JavaScript Fetch API requests and responses
In this article, you'll learn how to intercept JavaScript Fetch API calls. There are two types of events for which you may want...
Read more >
Troubleshooting common errors within Burp Suite - PortSwigger
In Burp, go to the Proxy > Intercept tab. If this is showing an intercepted HTTP request, then turn off interception (click on...
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