Skip to content Skip to sidebar Skip to footer

Unable To Capture Response.json() In Playwright

I am trying to capture json response using playwright. I keep on getting Promise pending. However under headless:false mode i can see the data is being received and populated on th

Solution 1:

The waitForResponse won't handle your async function. You could do something like this:

(async () => {
        let browser = await firefox.launch({headless: true, userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0'});
        let page = await browser.newPage();
        const promise page.waitForResponse(/abcd/); // This is a regex to match the urlawait page.goto('https://myurl.com', {waitUntil: 'networkidle', timeout: 30000});
        var response = await promise; // here we wait for the promise to be fullfiled. let resp = await response.json();
        console.log(resp);
        await browser.close();
})

Solution 2:

I tried this code. I get error at below code.

const promise page.waitForResponse(/abcd/); 

Post a Comment for "Unable To Capture Response.json() In Playwright"