Skip to content

Fix browser grab failing on Zone.js pages - #9995

Merged
AmethystLiang merged 1 commit into
mainfrom
bug-browser-grab-fails-on-angular-zone.js-pages
Jul 22, 2026
Merged

AmethystLiang merged 1 commit into
mainfrom
bug-browser-grab-fails-on-angular-zone.js-pages

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

Fixes issue #9947 where browser grab fails on pages using Zone.js-patched Promise. Zone.js replaces the global Promise with a non-native thenable; Electron's executeJavaScript boundary only unwraps native promises, so the wrapper object (with __zone_symbol__* fields) was serialized instead of the payload. Wrapping the promise-returning code in an async IIFE ensures it returns a native intrinsic promise that Electron always handles correctly.

Screenshots

No visual change.

Testing

  • Added high-quality regression tests thoroughly covering the ZoneAwarePromise scenario, including click, context menu, cancellation, and error paths
  • Tests verify the async wrapper produces a native promise, payloads cross the boundary correctly, and the raw Zone.js wrapper (regression case) is caught
  • pnpm build

AI Review Report

The fix is surgical: wrapping AWAIT_CLICK_SCRIPT in an async IIFE to ensure a native promise boundary crossing. Tests comprehensively model Zone.js's ZoneAwarePromise wrapper, verify all code paths (click, context menu, cancellation, rejection), and confirm serialization of the raw wrapper object is blocked.

Cross-platform verified: the fix is platform-agnostic—it addresses Electron's promise boundary and Zone.js behavior, not platform-specific paths, shortcuts, or shell behavior.

Security Audit

No new attack surfaces. Error handling is preserved; input validation remains with clampGrabPayload. Tests verify correct boundary crossing for both valid payloads and error cases.

Notes

This fixes compatibility with pages using Zone.js, primarily Angular applications. No impact on pages that don't patch Promise.

Zone.js patches the global Promise with a non-native thenable. When a bare
`new Promise(...)` crosses the Electron executeJavaScript boundary, it's
serialized as-is, losing { page, target } and exposing __zone_symbol__*
fields instead. Wrap in an async IIFE to return a native promise that
Electron always unwraps correctly.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 40408398-be74-49fd-842b-a47f2a16ac46

📥 Commits

Reviewing files that changed from the base of the PR and between c6d2803 and 365c53d.

📒 Files selected for processing (2)
  • src/main/browser/grab-guest-script.test.ts
  • src/main/browser/grab-guest-script.ts

📝 Walkthrough

Walkthrough

Refactors the injected awaitClick overlay script into an async IIFE that awaits its internal promise while preserving click, context-menu, cleanup, and cancellation behavior. Teardown documentation now identifies cancellation as resolution with __orcaCancelled. Adds isolated-realm regression tests using a Zone.js-like thenable to verify payload resolution, context-menu markers, cancellation, rejection, and the control behavior of a bare page-global promise.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing browser grab failures on Zone.js pages.
Description check ✅ Passed The description covers all required sections and includes testing, AI review, security, and notes, with only some test items left unchecked.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AmethystLiang
AmethystLiang merged commit b0e3616 into main Jul 22, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…#9995)

Zone.js patches the global Promise with a non-native thenable. When a bare
`new Promise(...)` crosses the Electron executeJavaScript boundary, it's
serialized as-is, losing { page, target } and exposing __zone_symbol__*
fields instead. Wrap in an async IIFE to return a native promise that
Electron always unwraps correctly.
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