Skip to content

fix(chrome): sort Playwright Chromium by revision, not lexically#74

Open
nsiddharth wants to merge 1 commit into
StarTrail-org:mainfrom
nsiddharth:fix/chrome-version-sort
Open

fix(chrome): sort Playwright Chromium by revision, not lexically#74
nsiddharth wants to merge 1 commit into
StarTrail-org:mainfrom
nsiddharth:fix/chrome-version-sort

Conversation

@nsiddharth

Copy link
Copy Markdown

What

_candidate_chrome_paths sorts Playwright's chromium-* browser
directories lexicographically:

paths.extend(sorted(glob.glob(str(cache_dir / rel_glob)), reverse=True))

The comment promises "Newest chromium-NNNN first," but a string sort
breaks that contract once the revision crosses the 3→4 digit boundary:
"chromium-999" ranks above "chromium-1187". Since find_chrome()
returns the first valid match, the resolver then silently selects an
older Chromium than the one the user just installed.

This triggers whenever two or more Playwright Chromium revisions are
cached and straddle that boundary — a normal state after playwright install upgrades, which leave older revisions in place.

Fix

Sort by the integer revision parsed from chromium-<n> instead of by
string. Paths without a recognizable revision sort last (-1) rather
than raising.

Test

Adds test_playwright_chromium_sorted_by_revision_not_lexically, which
feeds chromium-999, chromium-1187, chromium-1208 and asserts the
candidate list is newest-first. It fails on the old lexicographic sort
(chromium-999 landed first) and passes with this change. The existing
chrome-path tests are unaffected (6 passed).

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@nsiddharth is attempting to deploy a commit to the andylizf's projects Team on Vercel.

A member of the Team first needs to authorize it.

@andylizf andylizf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sort fix is correct — lexicographic sort breaks when Playwright revisions cross the 3→4 digit boundary (e.g. chromium-999 > chromium-1208). The _playwright_revision helper + test look good.

However, like #73, this PR is based on an older main and carries a large number of unrelated regressions (removes --cdp-url, --user-data-dir isolation, pre-commit hooks, reverts production URLs, etc.).

Could you rebase onto the latest origin/main so the PR contains only the chrome.py sort fix + test?

git fetch upstream main
git rebase upstream/main
git push --force-with-lease

_candidate_chrome_paths sorted Playwright's chromium-* matches as strings
(reverse=True), so once a revision crosses the 3->4 digit boundary
"chromium-999" ranks above "chromium-1187" and find_chrome() returns an
older browser than intended. Sort by the integer revision instead.
@nsiddharth nsiddharth force-pushed the fix/chrome-version-sort branch from 872bed3 to 0d12ed6 Compare June 23, 2026 06:27
@nsiddharth

Copy link
Copy Markdown
Author

Thanks for the review! Rebased onto the latest main (8d5c607) — the branch now carries only the two-file change (chrome.py sort fix + the test_chrome_paths.py test), so it sits cleanly on top of #75/#65/#49/#66/#76. Tests pass (6 passed) and ruff check / ruff format --check are clean against the new pre-commit hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants