I'm developing a WebScraping application using PlayWright, but when deploying it on heroku it can't install the browsers using the playwright install
command I got to run the command directly on the heroku console, it does the installation but also doesn't it worked out.
I'm using buildpack
https://github.com/mxschmitt/heroku-playwright-buildpack.git
on site is working perfectly, but when you play on heroku this problem, I've tried several solutions but none worked.
code snippet.
from playwright.sync_api import sync_playwright
with sync_playwright() as playwright:
browser = playwright.chromium.launch(chromium_sandbox=False)
context = browser.new_context()
page = context.new_page()
CodePudding user response:
Heroku's filesystem is both ephemeral and dyno-local. Any changes made to it are lost when the dyno restarts. More importantly at the moment, when you run something like heroku run bash
you don't connect to a running dyno. Instead, you get a separate one-off dyno.
Installing Chromium (or making any other filesystem changes) in such an environment will never affect what is available in your other dynos.
It looks like Playwright really wants to manage its own browser binaries. Your best bet might be to run playwright install
near the beginning of your script, e.g. something like this:
import subprocess
from playwright.sync_api import sync_playwright
subprocess.run(["playwright", "install"])
with sync_playwright() as playwright:
# ...
This should make sure that the required binaries are always available at runtime.