Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
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

Can waitForResponse take a promise instead of function or url? #4323

Open
techsin opened this issue Apr 22, 2019 · 6 comments · May be fixed by #5008

Comments

@techsin
Copy link

@techsin techsin commented Apr 22, 2019

Tell us about your environment:

  • Puppeteer version: 1.14
  • Platform / OS version: Windows
  • Node.js version: 10

What steps will reproduce the problem?
try to pass a promise to await page.waitForResponse(response => condition) instead of urlOrPredicate.

What is the expected result?
expect async function to work

What happens instead?
no waiting as promise gets eval to truthy.

response object has text method which is a promise to use that i need callback to be promise as well.. but if i make callback to be promise it breaks the waitForResponse function

@aslushnikov

This comment has been minimized.

Copy link
Collaborator

@aslushnikov aslushnikov commented Apr 22, 2019

@techsin why do you need to return a promise? Can you share an example?

@techsin

This comment has been minimized.

Copy link
Author

@techsin techsin commented Apr 23, 2019

i wanted to do response.text() which returns a promise. I wanted to return true or false based on what's inside text(). can't wait for promise to be resolved if original function isn't promise based.

eventually had to go with page.on('response'....

        await (new Promise(function (resolve, reject) {
            let listener = async (response) => {
                let url = 'https://www.example.com/';
                if (url == response.url()) {
                    try {
                        let json = JSON.parse(await response.text());
                        if (json.data.abc) {
                            ...
                            page.removeListener('response', listener);
                            resolve();
                        }
                    } catch (error) {
                        console.log(error);
                    }
                }
            };
            page.on('response', listener);
        }));

@techsin

This comment has been minimized.

Copy link
Author

@techsin techsin commented Apr 23, 2019

there is no way to do this for example

await page.waitForResponse(response => await response.text());
@aslushnikov

This comment has been minimized.

Copy link
Collaborator

@aslushnikov aslushnikov commented Apr 23, 2019

@techsin Well, that's very fair!

@rodoabad

This comment has been minimized.

Copy link

@rodoabad rodoabad commented Jun 22, 2019

Any update on this?

What about...

await page.waitForResponse('/user', () => customBody);

@aslushnikov

@jamesgeorge007

This comment has been minimized.

Copy link
Contributor

@jamesgeorge007 jamesgeorge007 commented Aug 16, 2019

@aslushnikov I would love to give this one a try. It would be great if you could guide me (files to work upon) as I'm new to the code-base.

@josalmi josalmi linked a pull request that will close this issue Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.