fix(templates): Pin Playwright to base image version for templates#1996
Conversation
The project template Dockerfile relied on a `sed` substitution to align the installed playwright version with the browser binaries baked into the `apify/actor-python-playwright*` base images. That substitution only rewrites a line starting with `playwright==`, but neither `requirements.txt` (pip) nor the exported `pyproject.toml`/`poetry.lock` reliably pin playwright directly — it is pulled in transitively via `crawlee[playwright]`. As a result pip installed the latest playwright release, replacing the version that matches the base image's browser binaries and causing a protocol mismatch (e.g. `Browser.setDefaultViewport` errors with camoufox). Replace the fragile `sed` trick in the pip and poetry branches with the same explicit pin already used by the uv branch: snapshot the base image's pre-installed playwright version, then force-reinstall that exact version after dependency installation. Non-playwright base images have no playwright pre-installed, so the pin is skipped there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012xSK5xwEhCUXbAeC9SVf29
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1996 +/- ##
==========================================
+ Coverage 93.08% 93.34% +0.25%
==========================================
Files 167 179 +12
Lines 11770 12482 +712
==========================================
+ Hits 10956 11651 +695
- Misses 814 831 +17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ip/poetry The previous attempt captured the base image's playwright version inside the dependency-install RUN. But the e2e template test patches the generated project (tests/e2e/project_template/utils.py) by injecting a `pip install ./crawlee-*.whl[playwright,...] --force-reinstall` step right after `COPY requirements.txt ./` / `COPY pyproject.toml ...`. That injected step resolves the unpinned playwright to the latest release *before* the snapshot ran, so the version captured (and pinned to) was the already-upgraded one — leaving the camoufox browser binary protocol mismatch unfixed. Move the snapshot into its own RUN placed before the COPY (and thus before any injected install step), writing it to /tmp/.base-playwright-version and reading it back when pinning — mirroring exactly what the working uv branch already does. This guarantees the captured version is the one baked into the base image and matching its browser binaries. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012xSK5xwEhCUXbAeC9SVf29
|
I see we still have this python specific setup in the docker images. We should align this, in JS we have docker image tags for playwright versions, and we pin those in the templates (together with the dependency version, to ensure they are aligned, plus we have a warning in the docker build if those versions are not the same). cc @vladfrangu
This is also weird, in JS, we don't dictate the playwright version, its a peer dependency, users need to install it explicitly. Can we do the same in python? |
### Description Base Docker images are bumping Playwright version automatically. This can make templates broken. Bumping the version in templates should be a manual step. (Should be used together with #1996 for fixing and stabilizing templates) ### Issues <!-- If applicable, reference any related GitHub issues --> - Closes: [295](apify/apify-actor-docker#295)
|
@vdusek We can fix the version in the template, for example, like this c25bd14 There are some edge cases about users who want a specific Playwright version or specific browser versions, but for that they have to do some custom Dockerfile changes. E2E tests green: https://github.com/apify/crawlee-python/actions/runs/28436119038 |
vdusek
left a comment
There was a problem hiding this comment.
A few questions / suggestions
|
New run of E2E tests with the latest commit: |
Description
playwright_versionto determine the version of the base image and also the version of installed Playwright