Skip to content

refactor(run): replace heredoc stdin with -c flag#188

Merged
sarath-menon merged 2 commits intomainfrom
fix/js-auto-wrap-return-iife
Apr 24, 2026
Merged

refactor(run): replace heredoc stdin with -c flag#188
sarath-menon merged 2 commits intomainfrom
fix/js-auto-wrap-return-iife

Conversation

@sarath-menon
Copy link
Copy Markdown
Contributor

@sarath-menon sarath-menon commented Apr 24, 2026

Summary

  • Drops the <<'PY' ... PY heredoc pattern entirely — no backward compatibility shim
  • browser-harness -c "code" is now the only invocation style
  • Simpler for agents to construct programmatically; no heredoc quoting pitfalls
  • Adds test_run.py with two tests covering the -c flag (red → green via TDD)

Test plan

  • test_c_flag_executes_code — code passed via -c runs and produces output
  • test_c_flag_does_not_read_stdin — stdin is never touched when -c is used
  • All 4 tests pass (uv run pytest test_js.py test_run.py -v)

🤖 Generated with Claude Code


Summary by cubic

Switches browser-harness to use a -c flag instead of heredoc stdin, making invocation simpler and more reliable. Also updates helpers.js() to accept top‑level return by auto‑wrapping the expression in an IIFE.

  • Migration

    • Use: browser-harness -c "print(page_info())". Heredoc stdin is no longer supported.
  • Bug Fixes

    • helpers.js() auto-wraps expressions containing return in an IIFE, so both document.title and const x = 1; return x work without CDP syntax errors.

Written for commit 0f20388. Summary will update on new commits.

sarath-menon and others added 2 commits April 24, 2026 15:47
Agents naturally write js() calls with top-level `return`, which is a
syntax error in Runtime.evaluate. js() now detects `return ` and wraps
the expression in an IIFE so both styles work without callers needing
to know the CDP constraint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Drops the <<'PY' heredoc pattern entirely. Agents now pass code via
`browser-harness -c "..."`, which is simpler to construct programmatically
and avoids heredoc quoting pitfalls.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sarath-menon sarath-menon merged commit 05d6eb8 into main Apr 24, 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

Development

Successfully merging this pull request may close these issues.

1 participant