Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitoring requested url returns "undefined" #8

Open
githubyiti opened this issue Feb 3, 2018 · 2 comments
Open

Monitoring requested url returns "undefined" #8

githubyiti opened this issue Feb 3, 2018 · 2 comments

Comments

@githubyiti
Copy link

githubyiti commented Feb 3, 2018

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();
})();
//////////////

@Neoglyph
Copy link

Neoglyph commented Feb 26, 2018

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?

@githubyiti
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants