docker-puppeteer icon indicating copy to clipboard operation
docker-puppeteer copied to clipboard

Monitoring requested url returns "undefined"

Open githubyiti opened this issue 7 years ago • 2 comments

Thank you for creating this easy to start docker image. While trying to use the following code to monitor the URL requested, the code returns:"undefined" How can I get the requested URLs? Thank you in advance.

//////////////////////////////
const puppeteer = require('puppeteer');
 (async() => {

    const browser = await puppeteer.launch({
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--enable-logging', '--v=1'
        ]
    });

    const page = await browser.newPage();
    await page.setRequestInterception(true);
    page.on('request', request => {
	    console.log(request.url);
            request.continue();
	  });

    await page.goto('https://camo.githubusercontent.com/05492f5e135964801f6cbe748dc7668925a965e2/687474703a2f2f646f636b6572692e636f2f696d6167652f616c656b7a6f6e6465722f707570706574656572', {waitUntil: 'networkidle2'});

    browser.close();
})();
//////////////

githubyiti avatar Feb 03 '18 12:02 githubyiti

Hey,

Url is actually a function, so using it the way you did would return [Function: url]. The correct way would be:

console.log(request.url());

The above code works just fine for me otherwise.

What is the command you use to run your script?

Neoglyph avatar Feb 26 '18 07:02 Neoglyph

Hi,

Thanks for not only giving the answer but also the reason!

So helpful for person just started learning javascript like me!

Thank you again for your time!

githubyiti avatar Feb 26 '18 09:02 githubyiti