Skip to content

[Bug]: Not able to install Playwright in Docker on M1 with aarch64 architecture #796

Closed

Description

@budsee

Playwright version

1.12.1

Operating system

MacOS

What browsers are you seeing the problem on?

Chromium

Other information

No response

What happened? / Describe the bug

Hi

I'm using playwright docker image here => https://hub.docker.com/_/microsoft-playwright

I encounter an issue where if I run playwright in the docker, I would have the below error

(node:97) UnhandledPromiseRejectionWarning: Error: Page closed
at CRSession. (/usr/local/lib/python3.8/dist-packages/playwright/driver/package/lib/server/chromium/crPage.js:341:60)
at Object.onceWrapper (events.js:420:28)
at CRSession.emit (events.js:326:22)
at /usr/local/lib/python3.8/dist-packages/playwright/driver/package/lib/server/chromium/crConnection.js:177:43
(node:97) 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: 1)

It run fine in my own machine (macOS m1). I research and saw that it is related to browser.close too early. However, I'm using pytest and is using playwright as sync and not async function since pytest has fixture which can yield the page and then do a browser close later. E.g code below:

pytest.fixture
def page():
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
yield page
browser.close()

Do we. know why the same code run fine in my local machine but not in playwright docker?

Code snippet to reproduce your bug

No response

Relevant log output

No response

Activity

  1. mxschmitt commented on Jul 7, 2021

    @mxschmitt
    Contributor

    Hi, would be great if you could provide us more logs using the DEBUG=pw:api environment variable, there we should see the API calls.

    Also I'm curious why you are not using the official Pytest plugin for Playwright: https://github.com/microsoft/playwright-pytest

  2. budsee commented on Jul 7, 2021

    @budsee
    Author

    Hi

    The logs are huge, so I pipe to a file and attached here => logs.txt

    Ah it's because I'm using pytest-bdd to be exact. playwright-pytest does not seem to work with pytest-bdd

  3. mxschmitt commented on Jul 7, 2021

    @mxschmitt
    Contributor

    From a short investigation, in the logs I can see a Chromium Stacktrace.

    Stacktrace
    E       playwright._impl._api_types.Error: Protocol error (Target.createTarget): Browser closed.
    E       ==================== Browser output: ====================
    E       [pid=7450][err] [0707/092357.911702:WARNING:gpu_process_host.cc(1308)] The GPU process has crashed 3 time(s)
    E       [pid=7450][err] [0707/092357.914350:ERROR:gpu_process_host.cc(989)] GPU process launch failed: error_code=1002
    E       [pid=7450][err] [0707/092357.914615:WARNING:gpu_process_host.cc(1308)] The GPU process has crashed 4 time(s)
    E       [pid=7450][err] [0707/092357.916485:ERROR:gpu_process_host.cc(989)] GPU process launch failed: error_code=1002
    E       [pid=7450][err] base::debug::StackTrace::StackTrace()
    E       [pid=7450][err] microsoft/playwright#2 0x0040065aba21 [0707/092357.916915:WARNING:gpu_process_host.cc(1308)] The GPU process has crashed 5 time(s)
    E       [pid=7450][err] [0707/092357.919388:ERROR:gpu_process_host.cc(989)] GPU process launch failed: error_code=1002
    E       [pid=7450][err] [0707/092357.919652:WARNING:gpu_process_host.cc(1308)] The GPU process has crashed 6 time(s)
    E       [pid=7450][err] [0707/092357.926915:ERROR:gpu_process_host.cc(989)] GPU process launch failed: error_code=1002
    E       [pid=7450][err] [0707/092357.927401:WARNING:gpu_process_host.cc(1308)] The GPU process has crashed 7 time(s)
    E       [pid=7450][err] [0707/092357.940677:ERROR:gpu_process_host.cc(989)] GPU process launch failed: error_code=1002
    E       [pid=7450][err] [0707/092357.940735:WARNING:gpu_process_host.cc(1308)] The GPU process has crashed 8 time(s)
    E       [pid=7450][err] base::debug::(anonymous namespace)::StackDumpSignalHandler()
    E       [pid=7450][err] microsoft/playwright#3 0x00400dd6b3c0 [0707/092357.957861:ERROR:gpu_process_host.cc(989)] GPU process launch failed: error_code=1002
    E       [pid=7450][err] [0707/092357.957920:WARNING:gpu_process_host.cc(1308)] The GPU process has crashed 9 time(s)
    E       [pid=7450][err] <unknown>
    E       [pid=7450][err] microsoft/playwright#4 0x00400dd197b2 <unknown>
    E       [pid=7450][err] microsoft/playwright#5 0x00400dd1c61b <unknown>
    E       [pid=7450][err] microsoft/playwright#6 0x00400dd27d37 <unknown>
    E       [pid=7450][err] microsoft/playwright#7 0x00400edd08b8 _dl_catch_exception
    E       [pid=7450][err] microsoft/playwright#8 0x00400dd275fa <unknown>
    E       [pid=7450][err] microsoft/playwright#9 0x00400dd4f34c <unknown>
    E       [pid=7450][err] microsoft/playwright#10 0x00400edd08b8 _dl_catch_exception
    E       [pid=7450][err] microsoft/playwright#11 0x00400edd0983 _dl_catch_error
    E       [pid=7450][err] microsoft/playwright#12 0x00400dd4fb59 <unknown>
    E       [pid=7450][err] microsoft/playwright#13 0x00400dd4f3da dlopen
    E       [pid=7450][err] microsoft/playwright#14 0x004003cefa70 LibUdev0Loader::Load()
    E       [pid=7450][err] microsoft/playwright#15 0x004003cee9e4 device::Udev1Loader::Init()
    E       [pid=7450][err] microsoft/playwright#16 0x004003ceea49 device::UdevLoader::Get()
    E       [pid=7450][err] microsoft/playwright#17 0x004003cee119 device::udev_new()
    E       [pid=7450][err] microsoft/playwright#18 0x004003ceedf7 device::UdevWatcher::StartWatching()
    E       [pid=7450][err] microsoft/playwright#19 0x004003da3ed5 media::DeviceMonitorLinux::BlockingTaskRunnerHelper::Initialize()
    E       [pid=7450][err] microsoft/playwright#20 0x00400656eb73 base::TaskAnnotator::RunTask()
    E       [pid=7450][err] microsoft/playwright#21 0x004006585ba7 base::internal::TaskTracker::RunContinueOnShutdown()
    E       [pid=7450][err] microsoft/playwright#22 0x00400658568e base::internal::TaskTracker::RunTask()
    E       [pid=7450][err] microsoft/playwright#23 0x0040065bc50e base::internal::TaskTrackerPosix::RunTask()
    E       [pid=7450][err] microsoft/playwright#24 0x004006585318 base::internal::TaskTracker::RunAndPopNextTask()
    E       [pid=7450][err] microsoft/playwright#25 0x004006590ead base::internal::WorkerThread::RunWorker()
    E       [pid=7450][err] microsoft/playwright#26 0x004006590bad base::internal::WorkerThread::RunPooledWorker()
    E       [pid=7450][err] microsoft/playwright#27 0x0040065bcd5c base::(anonymous namespace)::ThreadFunc()
    E       [pid=7450][err] microsoft/playwright#28 0x00400dd5f609 start_thread
    E       [pid=7450][err] microsoft/playwright#29 0x00400ed8f293 clone
    E       [pid=7450][err]   r8: 00000000effffef5  r9: 0000000070000022 r10: 00000040172c6000 r11: 0000000000000032
    E       [pid=7450][err]  r12: 000033aa00424000 r13: 000000006ffffeff r14: 0000004013a9a818 r15: 000000006ffffe35
    E       [pid=7450][err]   di: 000000006fffffff  si: 0000000000000029  bp: 0000004013a9a740  bx: 000000006ffffdff
    E       [pid=7450][err]   dx: 0000000000000000  ax: 0000061d0000061c  cx: 000033aa00424040  sp: 0000004013a9a5f0
    E       [pid=7450][err]   ip: 000000400dd197b2 efl: 0000000000000202 cgf: 002b000000000033 erf: 0000000000000004
    E       [pid=7450][err]  trp: ffffffffffffffff msk: 0000000000000000 cr2: 0000061d00000624
    E       [pid=7450][err] [end of stack trace]
    E       [pid=7450][err] qemu: uncaught target signal 11 (Segmentation fault) - core dumped
    

    This looks like a Docker bug. See the following related issues:

    Also it seems you can workaround it by passing args=["--disable-gpu"] when launching the browser or we would need to create Docker images for the ARM64 architecture.

    Another workaround which might work is using the Docker image ubuntu:focal instead and installing Playwright in there manually and the dependencies via playwright install and playwright install-deps. See here for docs.

  4. budsee commented on Jul 7, 2021

    @budsee
    Author

    Thanks for checking. Using args=["--disable-gpu"] does not help.
    Please find the attached logs for this => logs.txt

    I triedubuntu:focaldocker image before but I have the below playwright version install error where I can't install the latest version and stuck with 0.162.2 only

    > [ 9/12] RUN pip install playwright==1.12.1: microsoft/playwright#12 1.281 ERROR: Could not find a version that satisfies the requirement playwright==1.12.1 (from versions: 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.7, 0.0.8, 0.0.9, 0.0.10, 0.0.11, 0.0.12, 0.0.13, 0.0.14, 0.0.15, 0.0.16, 0.0.17, 0.0.18, 0.7.0, 0.7.1, 0.8.0, 0.140.0, 0.142.0, 0.142.1, 0.142.2, 0.142.3, 0.150.0, 0.151.0, 0.151.1, 0.152.0, 0.162.0, 0.162.1, 0.162.2) microsoft/playwright#12 1.282 ERROR: No matching distribution found for playwright==1.12.1

  5. mxschmitt commented on Jul 7, 2021

    @mxschmitt
    Contributor

    Could you provide us the output of pip debug --verbose?

  6. budsee commented on Jul 7, 2021

    @budsee
    Author

    Here it is. What does this mean? This also only happen in docker only.

    pip debug --verbose

    Traceback (most recent call last):
      File "/usr/bin/pip", line 11, in <module>
        load_entry_point('pip==20.0.2', 'console_scripts', 'pip')()
      File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
        command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
      File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
        module = importlib.import_module(module_path)
      File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
      File "<frozen importlib._bootstrap>", line 991, in _find_and_load
      File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 848, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/usr/lib/python3/dist-packages/pip/_internal/commands/debug.py", line 11, in <module>
        from pip._vendor.certifi import where
    ModuleNotFoundError: No module named 'pip._vendor.certifi'
    
  7. mxschmitt commented on Jul 7, 2021

    @mxschmitt
    Contributor

    Seems like the PIP installation inside the Docker container (also the official image) seems broken. Could you try executing this beforehand inside the container?

    curl -sS https://bootstrap.pypa.io/get-pip.py | python

  8. budsee commented on Jul 7, 2021

    @budsee
    Author

    Does not seem to help

    root@db8d954583cc:/# curl -sS https://bootstrap.pypa.io/get-pip.py | python3
    Collecting pip
      Using cached pip-21.1.3-py3-none-any.whl (1.5 MB)
    Installing collected packages: pip
      Attempting uninstall: pip
        Found existing installation: pip 21.1.3
        Uninstalling pip-21.1.3:
          Successfully uninstalled pip-21.1.3
    Successfully installed pip-21.1.3
    

    root@db8d954583cc:/# pip install playwright==1.21.1 ERROR: Could not find a version that satisfies the requirement playwright==1.21.1 (from versions: 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.7, 0.0.8, 0.0.9, 0.0.10, 0.0.11, 0.0.12, 0.0.13, 0.0.14, 0.0.15, 0.0.16, 0.0.17, 0.0.18, 0.7.0, 0.7.1, 0.8.0, 0.140.0, 0.142.0, 0.142.1, 0.142.2, 0.142.3, 0.150.0, 0.151.0, 0.151.1, 0.152.0, 0.162.0, 0.162.1, 0.162.2) ERROR: No matching distribution found for playwright==1.21.1

  9. mxschmitt commented on Jul 7, 2021

    @mxschmitt
    Contributor

    And what is the output for pip debug --verbose there?

    Background: pip debug will log the supported architectures, based on that we can see where the problem is.

  10. budsee commented on Jul 7, 2021

    @budsee
    Author

    Here's the updated one => logs.txt

  11. changed the title [-]Playwright Docker throwing UnhandledPromiseRejectionWarning: Error: Page closed[/-] [+][Bug]: Not able to install Playwright in Docker on M1 with aarch64 architecture[/+] on Jul 7, 2021
  12. kumaraditya303 commented on Jul 8, 2021

    @kumaraditya303
    Contributor

    budsee As per the logs, on apple m1 the docker runs natively with arm64 but currently playwright only supports x86_64 on linux docker, if you want to run it currently then you need to emulate x86 with qemu.

  13. budsee commented on Jul 8, 2021

    @budsee
    Author

    Thanks! Will there be any future plan to incorporate arm64 into the docker anytime soon?

  14. mxschmitt commented on Jul 29, 2021

    @mxschmitt
    Contributor

    Since the Python image is based on the upstream one, I will close this one here and we will track it upstream: microsoft/playwright#7723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions