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

playwright.helper.Error: Navigation failed because page crashed! #4549

Closed
yshalsager opened this issue Nov 29, 2020 · 12 comments
Closed

playwright.helper.Error: Navigation failed because page crashed! #4549

yshalsager opened this issue Nov 29, 2020 · 12 comments

Comments

@yshalsager
Copy link

I am running Python 3.8.5 on Ubuntu 20.04.1 and playwright==0.162.1.
I have a pretty complicated script that navigates through many pages of a given website. After navigating for a while (with goto method) playwright suddenly returns playwright.helper.Error: Navigation failed because page crashed! and skip to the next page then does the same thing. This happens randomly. There's no certain way to replicate it. Some of my script tests were totally fine (more than 200 pages navigation per run on both Chrome and Firefox non-headless mode).

Traceback with playwright debugging (some info are removed)

  pw:api   "load" event fired +0ms
Traceback (most recent call last):
  File "/home/x/y/z/a/pages/mobile/somepage.py", line 66, in create
    await self.open(self.url)
  File "/home/x/y/a/common/base_page.py", line 25, in open
    await browser.goto(url)
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/async_api.py", line 4037, in goto
    await self._impl_obj.goto(
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/page.py", line 451, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/frame.py", line 116, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/connection.py", line 39, in send
    result = await callback.future
playwright.helper.Error: Navigation failed because page crashed!
  pw:api   retrieving innerHTML from "html" +556ms
  pw:api   selector resolved to <html lang="en">…</html> +6ms
(node:50631) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at doWrite (_stream_writable.js:399:19)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Socket.Writable.write (_stream_writable.js:318:11)
    at Transport.send (/snapshot/playwright-cli/node_modules/playwright/lib/protocol/transport.js:38:25)
    at DispatcherConnection.onmessage (/snapshot/playwright-cli/lib/driver.js:49:61)
    at DispatcherConnection.sendMessageToClient (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:129:14)
    at WorkerDispatcher._dispatchEvent (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:70:26)
    at CRServiceWorker.<anonymous> (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/pageDispatcher.js:213:58)
    at CRServiceWorker.emit (events.js:315:20)
    at CRBrowser._onDetachedFromTarget (/snapshot/playwright-cli/node_modules/playwright/lib/server/chromium/crBrowser.js:190:27)

common/base_page.py open function is nothing special.

    async def open(url):
        browser = await Browser.get_browser()
        await browser.goto(url)
        await browser.waitForSelector('body')

If any other info is needed please let me know.

@yeducom
Copy link

yeducom commented Nov 30, 2020

mac FileNotFoundError: [Errno 2] No such file or directory: '/Users/apple/Library/Python/3.8/lib/python/site-packages/playwright/driver/playwright-cli'

@kumaraditya303
Copy link
Contributor

kumaraditya303 commented Nov 30, 2020 via email

@yeducom
Copy link

yeducom commented Nov 30, 2020

11.0.1

@kumaraditya303
Copy link
Contributor

11.0.1

@yeducom Currently MacOS Big Sur isn't supported See microsoft/playwright-python#325

@kumaraditya303
Copy link
Contributor

I am running Python 3.8.5 on Ubuntu 20.04.1 and playwright==0.162.1.
I have a pretty complicated script that navigates through many pages of a given website. After navigating for a while (with goto method) playwright suddenly returns playwright.helper.Error: Navigation failed because page crashed! and skip to the next page then does the same thing. This happens randomly. There's no certain way to replicate it. Some of my script tests were totally fine (more than 200 pages navigation per run on both Chrome and Firefox non-headless mode).

Traceback with playwright debugging (some info are removed)

  pw:api   "load" event fired +0ms
Traceback (most recent call last):
  File "/home/x/y/z/a/pages/mobile/somepage.py", line 66, in create
    await self.open(self.url)
  File "/home/x/y/a/common/base_page.py", line 25, in open
    await browser.goto(url)
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/async_api.py", line 4037, in goto
    await self._impl_obj.goto(
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/page.py", line 451, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/frame.py", line 116, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/connection.py", line 39, in send
    result = await callback.future
playwright.helper.Error: Navigation failed because page crashed!
  pw:api   retrieving innerHTML from "html" +556ms
  pw:api   selector resolved to <html lang="en">…</html> +6ms
(node:50631) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at doWrite (_stream_writable.js:399:19)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Socket.Writable.write (_stream_writable.js:318:11)
    at Transport.send (/snapshot/playwright-cli/node_modules/playwright/lib/protocol/transport.js:38:25)
    at DispatcherConnection.onmessage (/snapshot/playwright-cli/lib/driver.js:49:61)
    at DispatcherConnection.sendMessageToClient (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:129:14)
    at WorkerDispatcher._dispatchEvent (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:70:26)
    at CRServiceWorker.<anonymous> (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/pageDispatcher.js:213:58)
    at CRServiceWorker.emit (events.js:315:20)
    at CRBrowser._onDetachedFromTarget (/snapshot/playwright-cli/node_modules/playwright/lib/server/chromium/crBrowser.js:190:27)

common/base_page.py open function is nothing special.

    async def open(url):
        browser = await Browser.get_browser()
        await browser.goto(url)
        await browser.waitForSelector('body')

If any other info is needed please let me know.

There isn't any method get_browser() in API of playwright

@yshalsager
Copy link
Author

I am running Python 3.8.5 on Ubuntu 20.04.1 and playwright==0.162.1.
I have a pretty complicated script that navigates through many pages of a given website. After navigating for a while (with goto method) playwright suddenly returns playwright.helper.Error: Navigation failed because page crashed! and skip to the next page then does the same thing. This happens randomly. There's no certain way to replicate it. Some of my script tests were totally fine (more than 200 pages navigation per run on both Chrome and Firefox non-headless mode).
Traceback with playwright debugging (some info are removed)

  pw:api   "load" event fired +0ms
Traceback (most recent call last):
  File "/home/x/y/z/a/pages/mobile/somepage.py", line 66, in create
    await self.open(self.url)
  File "/home/x/y/a/common/base_page.py", line 25, in open
    await browser.goto(url)
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/async_api.py", line 4037, in goto
    await self._impl_obj.goto(
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/page.py", line 451, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/frame.py", line 116, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "/home/x/y/venv/lib/python3.8/site-packages/playwright/connection.py", line 39, in send
    result = await callback.future
playwright.helper.Error: Navigation failed because page crashed!
  pw:api   retrieving innerHTML from "html" +556ms
  pw:api   selector resolved to <html lang="en">…</html> +6ms
(node:50631) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at doWrite (_stream_writable.js:399:19)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Socket.Writable.write (_stream_writable.js:318:11)
    at Transport.send (/snapshot/playwright-cli/node_modules/playwright/lib/protocol/transport.js:38:25)
    at DispatcherConnection.onmessage (/snapshot/playwright-cli/lib/driver.js:49:61)
    at DispatcherConnection.sendMessageToClient (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:129:14)
    at WorkerDispatcher._dispatchEvent (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:70:26)
    at CRServiceWorker.<anonymous> (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/pageDispatcher.js:213:58)
    at CRServiceWorker.emit (events.js:315:20)
    at CRBrowser._onDetachedFromTarget (/snapshot/playwright-cli/node_modules/playwright/lib/server/chromium/crBrowser.js:190:27)

common/base_page.py open function is nothing special.

    async def open(url):
        browser = await Browser.get_browser()
        await browser.goto(url)
        await browser.waitForSelector('body')

If any other info is needed please let me know.

There isn't any method get_browser() in API of playwright

Sorry, I forgot to mention it.
It's nothing more than a method for returning the current BrowserType instance created with launch method.

@pavelfeldman
Copy link
Member

It looks like you are hitting a renderer crash (sad tab), so it would be great if there was a repro so that we could narrow it down. Also, any reason you navigate the same page so many times, could you share your use case?

@yshalsager
Copy link
Author

It looks like you are hitting a renderer crash (sad tab), so it would be great if there was a repro so that we could narrow it down. Also, any reason you navigate the same page so many times, could you share your use case?

Basically, the script is testing some online store coupons and have to go through a large list of products (1500+).
Each product needs at least 3 navigation steps (product page - checkout - cart).

@pavelfeldman
Copy link
Member

You are hitting the out-of-memory error due to collected state in the context. You should use new context for each product to make tests isolated and more real. I.e. browser.newContext followed by a context.newPage, then your navigation steps. Don't forget to close the context (or page) after each test. That would isolate tests and would make sure state does not collect over time. If you need to sign it only once for that, there are ways to inject cookies / storage in the new context for each test so that you did not need to log in over and over.

We currently retain all the resource handles within the context, that adds over time. We'll fix it upstream, but you could switch to a context-per-test for now to work around it, it is how it is supposed to be anyways.

@pavelfeldman pavelfeldman transferred this issue from microsoft/playwright-python Nov 30, 2020
@yshalsager
Copy link
Author

You are hitting the out-of-memory error due to collected state in the context. You should use new context for each product to make tests isolated and more real. I.e. browser.newContext followed by a context.newPage, then your navigation steps. Don't forget to close the context (or page) after each test. That would isolate tests and would make sure state does not collect over time. If you need to sign it only once for that, there are ways to inject cookies / storage in the new context for each test so that you did not need to log in over and over.

We currently retain all the resource handles within the context, that adds over time. We'll fix it upstream, but you could switch to a context-per-test for now to work around it, it is how it is supposed to be anyways.

Thanks for the clarification, I will update my code as soon as possible and see if everything works as it should.

@yshalsager
Copy link
Author

You are hitting the out-of-memory error due to collected state in the context. You should use new context for each product to make tests isolated and more real. I.e. browser.newContext followed by a context.newPage, then your navigation steps. Don't forget to close the context (or page) after each test. That would isolate tests and would make sure state does not collect over time. If you need to sign it only once for that, there are ways to inject cookies / storage in the new context for each test so that you did not need to log in over and over.

We currently retain all the resource handles within the context, that adds over time. We'll fix it upstream, but you could switch to a context-per-test for now to work around it, it is how it is supposed to be anyways.

Done updating my code, and it's working perfectly now. I have run a test with more than 1500 products at night and nothing went wrong thankfully.

@pavelfeldman
Copy link
Member

Yay!

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

4 participants