Installing Playwright on Streamlit Cloud

I’ve had no problem using Playwright on Streamlit locally. But when I try to deploy the app using Github (and installed all dependencies via requirements.txt), it doesn’t seem to work because Playwright requires the additional “playwright install” command via the terminal to install browser binaries.

I get the following error:

2022-09-22 06:10:47.874 Uncaught app exception

Traceback (most recent call last):

  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 556, in _run_script

    exec(code, module.__dict__)

  File "/app/feedings/main_pw.py", line 14, in <module>

    browser = p.chromium.launch()

  File "/home/appuser/venv/lib/python3.9/site-packages/playwright/sync_api/_generated.py", line 11678, in launch

    self._sync(

  File "/home/appuser/venv/lib/python3.9/site-packages/playwright/_impl/_sync_base.py", line 104, in _sync

    return task.result()

  File "/home/appuser/venv/lib/python3.9/site-packages/playwright/_impl/_browser_type.py", line 93, in launch

    Browser, from_channel(await self._channel.send("launch", params))

  File "/home/appuser/venv/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 43, in send

    return await self._connection.wrap_api_call(

  File "/home/appuser/venv/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 387, in wrap_api_call

    return await cb()

  File "/home/appuser/venv/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 78, in inner_send

    result = next(iter(done)).result()

playwright._impl._api_types.Error: Executable doesn't exist at /home/appuser/.cache/ms-playwright/chromium-1024/chrome-linux/chrome

╔════════════════════════════════════════════════════════════╗

║ Looks like Playwright was just installed or updated.       ║

║ Please run the following command to download new browsers: ║

║                                                            ║

║     playwright install                                     ║

║                                                            ║

║ <3 Playwright Team                                         ║

╚════════════════════════════════════════════════════════════╝

Is there a simple solution for this?

I got Playwright to work but not sure if this is the best solution. To overcome the above issue, I included

import os
os.system("playwright install")

at the top of my code, and added a packages.txt file to my Github containing:

libnss3
libnspr4
libatk1.0-0
libatk-bridge2.0-0
libcups2
libdrm2
libxkbcommon0
libxcomposite1
libxdamage1
libxfixes3
libxrandr2
libgbm1
libpango-1.0-0
libcairo2
libasound2
libatspi2.0-0
libwayland-client0