playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] response.json() promise rejection

Open sarut0bi opened this issue 5 years ago • 4 comments

Context:

  • Playwright Version: 1.4.1
  • Operating System: Windows
  • Node.js version: 14.15.1
  • Browser: Chromium
2021-08-31T10:35:08.152Z pw:api <= response.json failed
(node:5752) UnhandledPromiseRejectionWarning: response.json: Protocol error (Network.getResponseBody): No resource with given identifier found
at Page.<anonymous> (c:\Users\xx\xx\tests\browserAction.js:67:57)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5752) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 35)
(node:5752) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Code Snippet

...
        await page.on('requestfinished', async (request) => {
            if (request.url().match(/.*\/users\/me.*/)) {
                let response = await request.response();
                response = await response.json();
           }
...

Describe the bug

Promise is randomly rejected ... problem do not occurs if I replace await response.json(); by JSON.parse((await response.body()).toString());

sarut0bi avatar Aug 31 '21 10:08 sarut0bi

It may happen if your page navigates to another URL while you are trying to fetch the response body. Can you please test with the latest playwright and share the rest of the code snippet? Also could you run with DEBUG=pw:protocol and upload the log here?

yury-s avatar Aug 31 '21 19:08 yury-s

Here it is :)

2021-09-01T08:32:53.658Z pw:api waiting for selector "[data-test-id="xxx"]" to be visible
2021-09-01T08:32:53.659Z pw:api waiting for selector "[data-test-id="xxx"]" to be visible
2021-09-01T08:32:53.662Z pw:api   selector resolved to visible <button tabindex="0" role="menuitem" mat-menu-item="" ar…>…</button>
2021-09-01T08:32:53.667Z pw:api <= frame.waitForSelector succeeded
2021-09-01T08:32:53.667Z pw:api => elementHandle.click started
2021-09-01T08:32:53.667Z pw:api => page.waitForResponse started
2021-09-01T08:32:53.667Z pw:api => page.waitForResponse started
2021-09-01T08:32:53.668Z pw:api <= page.waitForResponse succeeded
2021-09-01T08:32:53.668Z pw:api attempting click action
2021-09-01T08:32:53.668Z pw:api   waiting for element to be visible, enabled and stable
2021-09-01T08:32:53.668Z pw:api waiting for response /.*\/me.*/
2021-09-01T08:32:53.697Z pw:api     element is not stable - waiting...
2021-09-01T08:32:53.775Z pw:api   "networkidle" event fired
2021-09-01T08:32:53.816Z pw:api   element is visible, enabled and stable
2021-09-01T08:32:53.816Z pw:api   scrolling into view if needed
2021-09-01T08:32:53.817Z pw:api   done scrolling
2021-09-01T08:32:53.818Z pw:api   checking that element receives pointer events at (1124.28,260)
2021-09-01T08:32:53.822Z pw:api   element does receive pointer events
2021-09-01T08:32:53.822Z pw:api   performing click action
2021-09-01T08:32:53.834Z pw:api   click action done
2021-09-01T08:32:53.834Z pw:api   waiting for scheduled navigations to finish
2021-09-01T08:32:53.835Z pw:api => immediate._onImmediate started
2021-09-01T08:32:53.836Z pw:api <= immediate._onImmediate succeeded
2021-09-01T08:32:53.839Z pw:api   navigations have finished
2021-09-01T08:32:53.839Z pw:api <= elementHandle.click succeeded
2021-09-01T08:32:53.913Z pw:api <= page.waitForResponse succeeded
2021-09-01T08:32:53.915Z pw:api => immediate._onImmediate started
2021-09-01T08:32:53.915Z pw:api => immediate._onImmediate started
2021-09-01T08:32:53.917Z pw:api <= immediate._onImmediate succeeded
2021-09-01T08:32:53.918Z pw:api => response.json started
2021-09-01T08:32:53.918Z pw:api <= immediate._onImmediate succeeded
2021-09-01T08:32:53.921Z pw:api <= response.json succeeded
2021-09-01T08:32:53.925Z pw:api => page.reload started
2021-09-01T08:32:53.926Z pw:api waiting for navigation until "load"
2021-09-01T08:32:53.936Z pw:api => immediate._onImmediate started
2021-09-01T08:32:53.936Z pw:api <= immediate._onImmediate succeeded
2021-09-01T08:32:53.989Z pw:api => immediate._onImmediate started
2021-09-01T08:32:53.989Z pw:api <= immediate._onImmediate succeeded
2021-09-01T08:32:53.989Z pw:api => response.json started
2021-09-01T08:32:54.001Z pw:api <= frame.waitForSelector failed
2021-09-01T08:32:54.001Z pw:api <= frame.waitForSelector failed
2021-09-01T08:32:54.001Z pw:api <= frame.waitForSelector failed
2021-09-01T08:32:54.001Z pw:api <= frame.waitForSelector failed
2021-09-01T08:32:54.001Z pw:api <= frame.waitForSelector failed
2021-09-01T08:32:54.009Z pw:api   navigated to "xxx"
2021-09-01T08:32:54.009Z pw:api   navigated to "xxx"
2021-09-01T08:32:54.010Z pw:api <= response.json failed
(node:3068) UnhandledPromiseRejectionWarning: response.json: Protocol error (Network.getResponseBody): No resource with given identifier found
at Page.<anonymous> (c:\Users\Amira\tms\tests\browserAction.js:66:57)
(node:3068) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 62)

sarut0bi avatar Sep 01 '21 08:09 sarut0bi

Here it is :)

I need DEBUG=pw:protocol not DEBUG=pw:api.

In any case it looks like my theory that the page navigates to another url while you are trying to retrieve response body from the previous page, could you check if this is true?

yury-s avatar Sep 01 '21 16:09 yury-s

We need more information to act on this report. Please file a new one and link to this issue when you get back to it!

pavelfeldman avatar Sep 07 '21 20:09 pavelfeldman