Skip to content

[Bug]: Pyinstaller ends up in Page.goto: Target page, context or browser has been closed #2683

Open
@yaniswang

Description

@yaniswang

Version

1.49.0

Steps to reproduce

Code: test.py

from playwright.sync_api import sync_playwright

ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'

with sync_playwright() as playwright:
    browser = playwright.chromium.launch(headless=True)

    context = browser.new_context(user_agent=ua)
    page = context.new_page()
    page.goto('https://www.google.com/')
    page.screenshot(path=f'test.png')
    browser.close()

env: Raspberry Pi

  1. python -m venv test
  2. export PLAYWRIGHT_BROWSERS_PATH=0
  3. python -m playwright install
  4. python test.py -> works
  5. pyinstaller -F test.py
  6. ./dist/test

Expected behavior

no error

Actual behavior

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    page.goto('https://www.baidu.com/')
  File "playwright/sync_api/_generated.py", line 9006, in goto
  File "playwright/_impl/_sync_base.py", line 115, in _sync
  File "playwright/_impl/_page.py", line 551, in goto
  File "playwright/_impl/_frame.py", line 145, in goto
  File "playwright/_impl/_connection.py", line 61, in send
  File "playwright/_impl/_connection.py", line 528, in wrap_api_call
playwright._impl._errors.TargetClosedError: Page.goto: Target page, context or browser has been closed
Call log:
  - navigating to "https://www.google.com/", waiting until "load"

[PYI-32348:ERROR] Failed to execute script 'test' due to unhandled exception!

Additional context

If execute the source code directly, the result is correct, but after packaging with pyinstaller, it is not correct.
The same code packaged under Windows, the results are also correct.

Environment

- Operating System: [Debian 6.1.31]
- CPU: [arm64]
- Browser: [chromium_headless_shell-1148]
- Python Version: [3.9.2]
- Other info:

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