Skip to content

fix: Upgrade browser-commander to v0.5.3 (fixes Playwright evaluate bug)#149

Merged
konard merged 4 commits intomainfrom
issue-148-75d40853070e
Jan 10, 2026
Merged

fix: Upgrade browser-commander to v0.5.3 (fixes Playwright evaluate bug)#149
konard merged 4 commits intomainfrom
issue-148-75d40853070e

Conversation

@konard
Copy link
Owner

@konard konard commented Jan 8, 2026

Summary

Fixes #148

Upgraded browser-commander from v0.3.0 to v0.5.3, which includes the upstream fix for the Playwright multi-argument evaluation bug.

Problem

When using Playwright engine with multiple arguments passed to safeEvaluate(), the automation crashed with:

SyntaxError: Failed to execute 'querySelectorAll' on 'Document':
'[data-qa="vacancy-serp__vacancy_response"],' is not a valid selector.

Root Cause

The browser-commander v0.3.0 package's PlaywrightAdapter.evaluateOnPage() incorrectly passed multiple arguments as a single array to page.evaluate(). Since Playwright only accepts a single argument, the function received the entire array as its first parameter instead of spread arguments.

When this array was passed to document.querySelectorAll(), JavaScript converted it to a string using toString(), which joins elements with commas. An empty array becomes an empty string, resulting in a trailing comma:

["[data-qa=...]", []].toString() // => "[data-qa=...],"

Solution

The upstream fix was released in browser-commander v0.5.1 and published to npm. The fix modifies PlaywrightAdapter.evaluateOnPage() to:

  1. Convert the function to a string
  2. Pass function string + args array as a single object to browser context
  3. Reconstruct the function in browser and call with spread arguments

This makes Playwright's behavior match Puppeteer's spread behavior without requiring changes to any call sites.

Changes

  • ✅ Upgraded browser-commander from ^0.3.0 to ^0.5.3
  • ✅ Removed patch-package from devDependencies
  • ✅ Removed patches/browser-commander+0.3.0.patch file
  • ✅ Removed postinstall script that applied patches
  • ✅ Removed experiment test script

Upstream Issue

The fix was implemented upstream in: link-foundation/browser-commander#16

Test Plan

  • All 327 existing tests pass
  • Lint passes
  • Dependencies install cleanly without patches
  • No patch-package warnings

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #148
@konard konard self-assigned this Jan 8, 2026
…uate

Fixes #148

## Problem
When using Playwright engine with multiple arguments passed to safeEvaluate(),
the automation crashed with:
"SyntaxError: Failed to execute 'querySelectorAll' on 'Document':
'[data-qa="vacancy-serp__vacancy_response"],' is not a valid selector."

## Root Cause
The browser-commander v0.3.0 package's PlaywrightAdapter.evaluateOnPage()
incorrectly passes multiple arguments as a single array to page.evaluate().
Playwright's evaluate() only accepts a single argument, so the function
receives the entire array as its first parameter instead of spread arguments.

When this array is passed to document.querySelectorAll(), JavaScript converts
it to a string using toString(), which joins elements with commas. An empty
array (like processedIds = []) becomes an empty string, resulting in a
trailing comma.

Evidence: ["selector", []].toString() => "selector,"

## Solution
Added a patch for browser-commander using patch-package that fixes the
PlaywrightAdapter.evaluateOnPage() method to properly handle multiple args:
1. Convert the function to a string
2. Pass function string + args array as a single object to browser context
3. Reconstruct the function in browser and call with spread arguments

This makes Playwright's behavior match Puppeteer's spread behavior without
requiring changes to any call sites.

## Changes
- patches/browser-commander+0.3.0.patch: Fix for multi-arg evaluate
- package.json: Added patch-package devDependency and postinstall script

## Testing
- All 327 tests pass
- Lint passes
- experiments/test-playwright-multi-args.mjs validates the fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] Error occurred: evaluate: SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '[data-qa="vacancy-serp__vacancy_response"],' is not a valid selector. fix: Patch browser-commander to fix trailing comma in Playwright evaluate Jan 8, 2026
@konard konard marked this pull request as ready for review January 8, 2026 17:26
@konard
Copy link
Owner Author

konard commented Jan 8, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.946101 USD
  • Calculated by Anthropic: $3.682392 USD
  • Difference: $-2.263710 (-38.07%)
    📎 Log file uploaded as GitHub Gist (611KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Owner Author

konard commented Jan 8, 2026

Please report issue there at: https://github.com/link-foundation/browser-commander

The issue must contain reproducible examples, workarounds and suggestions for fix the issue in code. So once it is fixed there we will be able to remove workaround here.

@konard konard marked this pull request as draft January 8, 2026 19:44
@konard
Copy link
Owner Author

konard commented Jan 8, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-08T19:44:43.630Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

@konard
Copy link
Owner Author

konard commented Jan 8, 2026

I've created the upstream issue as requested: link-foundation/browser-commander#15

The issue contains:

  • Bug description and root cause analysis
  • Reproducible example code
  • Real-world error that was occurring
  • The workaround/fix implementation
  • Test script to validate the fix
  • References to this issue and PR

Once the fix is merged upstream and a new version is released, we can remove the patch from this repository.

@konard konard marked this pull request as ready for review January 8, 2026 19:47
@konard
Copy link
Owner Author

konard commented Jan 8, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.983939 USD
  • Calculated by Anthropic: $1.162694 USD
  • Difference: $-0.821246 (-41.39%)
    📎 Log file uploaded as GitHub Gist (298KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Owner Author

konard commented Jan 9, 2026

There is new version available - https://github.com/link-foundation/browser-commander/releases/tag/v0.5.1, will it work as expected? Everything is solved?

@konard konard marked this pull request as draft January 9, 2026 15:03
@konard
Copy link
Owner Author

konard commented Jan 9, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-09T15:03:25.809Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

@konard
Copy link
Owner Author

konard commented Jan 9, 2026

Investigation Result

I investigated the browser-commander v0.5.1 release status:

✅ Good News

❌ Problem Found

The npm publishing failed for v0.5.1. From the CI logs:

npm error Access token expired or revoked. Please try logging in again.
npm error 404 Not Found - PUT https://registry.npmjs.org/browser-commander - Not found

The npm token has been revoked due to npm's security policy change (classic tokens were revoked, granular tokens now require 2FA and 90-day limits).

Current npm status:

  • Latest available: 0.4.0
  • v0.5.1 is NOT published to npm

Action Taken

I've created a new issue to report this: link-foundation/browser-commander#17

Next Steps

Once the npm token is refreshed and v0.5.1 is published to npm, we can:

  1. Update browser-commander dependency from ^0.3.0 to ^0.5.1
  2. Remove the patches/browser-commander+0.3.0.patch file
  3. Remove patch-package from devDependencies and postinstall script

For now, the patch in this PR remains necessary as a workaround until the upstream package is available on npm.

@konard konard marked this pull request as ready for review January 9, 2026 15:06
@konard
Copy link
Owner Author

konard commented Jan 9, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.765499 USD
  • Calculated by Anthropic: $0.931312 USD
  • Difference: $-0.834187 (-47.25%)
    📎 Log file uploaded as GitHub Gist (292KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Owner Author

konard commented Jan 10, 2026

Now it is released, check again.

@konard konard marked this pull request as draft January 10, 2026 14:31
@konard
Copy link
Owner Author

konard commented Jan 10, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-10T14:31:12.752Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

The upstream fix for Playwright's evaluateOnPage() trailing comma bug
has been released in browser-commander v0.5.1+ and is now available on npm.

Changes:
- Upgraded browser-commander from ^0.3.0 to ^0.5.3
- Removed patch-package and the browser-commander patch file
- Removed postinstall script that applied patches
- Removed test experiment script

The upstream fix in v0.5.1 addresses the same issue we were patching:
properly spreading multiple arguments to Playwright's evaluate() by
reconstructing the function in the browser context.

All 327 tests pass with the upstream fix.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review January 10, 2026 14:34
@konard
Copy link
Owner Author

konard commented Jan 10, 2026

✅ Issue Resolved with Upstream Fix

The issue has been resolved by upgrading to browser-commander v0.5.3, which includes the upstream fix for the Playwright multi-argument evaluation bug.

What Changed

  1. Upgraded browser-commander: ^0.3.0^0.5.3
  2. Removed patch workaround: No longer need patch-package or manual patches
  3. Clean solution: The fix is now maintained upstream

Verification

  • ✅ All 327 tests pass
  • ✅ Lint checks pass
  • ✅ CI pipeline passes
  • ✅ No more patch-package warnings

Upstream Fix Details

The fix was released in:

  • v0.5.1 (Jan 9): Fixed the trailing comma bug
  • v0.5.2 (Jan 10): Build script improvements
  • v0.5.3 (Jan 10): Documentation enhancements

The upstream issue was tracked at: link-foundation/browser-commander#15
And fixed in PR: link-foundation/browser-commander#16

This PR is now ready for final review and merge.

@konard konard changed the title fix: Patch browser-commander to fix trailing comma in Playwright evaluate fix: Upgrade browser-commander to v0.5.3 (fixes Playwright evaluate bug) Jan 10, 2026
@konard konard merged commit 633dbf2 into main Jan 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant