Skip to content

[Feature]: Use different PLAYWRIGHT_BROWSERS_PATH when using Pyinstaller #1001

@Brze0x

Description

@Brze0x

Your question

Python : 3.8.9

altgraph==0.17.2
future==0.18.2
greenlet==1.1.2
pefile==2021.9.3
playwright==1.16.1
pyee==8.2.2
pyinstaller==4.6
pyinstaller-hooks-contrib==2021.3
pywin32-ctypes==0.2.0
typing-extensions==3.10.0.2
websockets==10.0

Using pyinstaller for a project with playwright on the output, I get a large exe file size (137mb and if I use upx 134mb).
I understand that this is due to the fact that we are packaging chromium into exe.

pyinstaller I run with the following parameters(flags)

pyinstaller -y -F --add-data "venv/lib/site-packages/playwright/driver;playwright/driver" --upx-dir=X:\dev\upx-396 app.py

Is it possible to add chromium to a separate directory(for example: browsers\chrome-win) and run it via the executable_path parameter?

I mean that the project structure looks like this:
dist # compiled project
├── browsers
│⠀⠀⠀└── chrome-win
│⠀⠀⠀⠀⠀⠀⠀├── chrome.exe
│⠀⠀⠀⠀⠀⠀⠀└── ...
├── data
│⠀⠀⠀├── test.json
│⠀⠀⠀└── file.txt
└── app.exe

This way we could detach the chrome and thereby reduce the size of the exe file.

Also now if I use executable_path = 'browsers\chrome-win':
I took chromium from https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win_x64/ and just copied the content to browser\chrome-win directories
This code is just for example

def main(url: str):
    with func.sync_playwright() as p:
        browser = p.chromium.launch(headless=False, executable_path='browsers\chrome-win')
        page = browser.new_page()
        page.goto(url=url)
        print(page.title())
        page.wait_for_timeout(10000)

I get the following error:

Traceback (most recent call last):
  File ".\app.py", line 37, in <module>
    connect_to_clevver(url=s.URL)
  File ".\app.py", line 7, in connect_to_clevver
    browser = p.chromium.launch(headless=False, executable_path='browser\chrome-win')
  File "F:\Python Project\pw-test\venv\lib\site-packages\playwright\sync_api\_generated.py", line 11164, in launch
    self._sync(
  File "F:\Python Project\pw-test\venv\lib\site-packages\playwright\_impl\_sync_base.py", line 111, in _sync
    return task.result()
  File "F:\Python Project\pw-test\venv\lib\site-packages\playwright\_impl\_browser_type.py", line 88, in launch
    return from_channel(await self._channel.send("launch", params))
  File "F:\Python Project\pw-test\venv\lib\site-packages\playwright\_impl\_connection.py", line 39, in send
    return await self.inner_send(method, params, False)
  File "F:\Python Project\pw-test\venv\lib\site-packages\playwright\_impl\_connection.py", line 63, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.Error: Failed to launch: Error: spawn browser\chrome-win ENOENT
=========================== logs ===========================
<launching> browser\chrome-win --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling 
--disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages 
--disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter 
--allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding 
--disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun 
--no-sandbox --user-data-dir=C:\Users\Us~1\AppData\Local\Temp\playwright_chromiumdev_profile-3zvqQg --remote-debugging-pipe --no-startup-window
[pid=N/A] starting temporary directories cleanup
[pid=N/A] finished temporary directories cleanup

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