Skip to content

fix: screenshot misidentifies relative dot-paths as CSS selectors - #499

Closed
bluzername wants to merge 1 commit into
garrytan:mainfrom
bluzername:fix/browse-screenshot-relative-path
Closed

bluzername wants to merge 1 commit into
garrytan:mainfrom
bluzername:fix/browse-screenshot-relative-path

Conversation

@bluzername

Copy link
Copy Markdown
Contributor

Problem

browse screenshot ./path/to/file.png fails with CSS parser error because the argument classifier treats any argument starting with . as a CSS class selector. Same problem with .gstack/screenshots/page.png.

screenshot: Unexpected token "/" while parsing css selector "./path/to/file.png"

Absolute paths like /tmp/file.png work fine because they dont start with ..

Root Cause

In browse/src/meta-commands.ts line 117, the condition arg.startsWith('.') catches both CSS selectors (.my-class) and relative file paths (./screenshots/page.png) without distinguishing them.

Fix

Added a file path check before the CSS selector check. If an argument contains / AND ends with an image/pdf extension (.png, .jpg, .jpeg, .webp, .pdf), it is unambiguously a file path and not a CSS selector.

const isFilePath = arg.includes('/') && /\.(png|jpe?g|webp|pdf)$/i.test(arg);

This is safe because:

  • CSS selectors like .menu-item never contain / (this is not valid CSS)
  • Real CSS selectors like .class dont end with .png
  • Relative paths like ./test.png always contain / and end with extension

The existing CSS selector detection stays unchanged for everything else - only file paths with / and image extension get special handling.

Testing

Added test case for ./browse-test-dotpath.png path (could not run full integration tests locally since Playwright browsers were not installed, but the logic is minimal and deterministic).

Before After
./path.png -> CSS selector -> parse error ./path.png -> file path -> works
.gstack/file.png -> CSS selector -> error .gstack/file.png -> file path -> works
.my-class -> CSS selector .my-class -> CSS selector (unchanged)
/tmp/file.png -> file path /tmp/file.png -> file path (unchanged)

Closes #495

@16francej

Copy link
Copy Markdown
Collaborator

Closing — the codebase has changed significantly since this was opened and this no longer applies to current main. Thanks for the contribution.

@16francej 16francej closed this Jul 14, 2026
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.

browse screenshot: relative paths starting with . are misidentified as CSS selectors

2 participants