Skip to content

fix(viewer): await setViewerUrl IPC before navigating iframe to prevent cross-origin SecurityError (#17982) - #18066

Merged
kevinushey merged 3 commits into
mainfrom
feature/fix-viewer-pane-race-condition
Jun 25, 2026
Merged

kevinushey merged 3 commits into
mainfrom
feature/fix-viewer-pane-race-condition

Conversation

@kevinushey

@kevinushey kevinushey commented Jun 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #17982

The viewer pane iframe could be blocked by Electron's navigation policy, causing cross-origin SecurityErrors when previewing markdown files or R Notebooks as HTML. The setViewerUrl IPC call is now awaited before the iframe navigates, ensuring the URL authority is registered in time.

Changes

  • src/node/desktop: Change setViewerUrl IPC from send to handle/invoke for synchronous result, ensuring the URL is registered before navigation
  • src/gwt: Update DesktopFrame interface to accept a callback after IPC completes; HTMLPreviewPanel and ViewerPresenter now await the IPC result before calling previewFrame_.setUrl()
  • e2e/rstudio/tests: Remove test.skip/test.fixme markers from markdown and rnotebook preview tests since the underlying issue is now fixed
  • NEWS.md: Added changelog entry

@kevinushey
kevinushey force-pushed the feature/fix-viewer-pane-race-condition branch from b6fe871 to 80eb3e6 Compare June 25, 2026 17:06
…nt cross-origin SecurityError (#17982)

The viewer pane iframe could be blocked by Electron's navigation policy,
causing cross-origin SecurityErrors when previewing markdown files or
R Notebooks as HTML. The setViewerUrl IPC call is now awaited before the
iframe navigates, ensuring the URL authority is registered in time.

- Change setViewerUrl IPC from send to handle/invoke for synchronous
  result, ensuring the URL is registered before navigation
- Update GWT DesktopFrame interface to accept a callback after IPC
- HTMLPreviewPanel and ViewerPresenter now await the IPC result
  before calling previewFrame_.setUrl()
- Remove test.skip/fixme markers from markdown and rnotebook preview
  tests since the underlying issue is now fixed
@kevinushey
kevinushey force-pushed the feature/fix-viewer-pane-race-condition branch from 80eb3e6 to 85c3c63 Compare June 25, 2026 17:09
…mport

Fix compilation errors in HTMLPreviewPanel and ViewerPresenter caused by
importing a non-existent org.rstudio.core.client.Command class. Switch to
the correct GWT class com.google.gwt.user.client.Command.
@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated multi-agent review. The fix itself is sound — deferring iframe navigation into the setViewerUrl IPC callback genuinely closes the race, since the renderer's invoke().then() only resolves after the main process records the viewer authority that allowNavigation consults.

Important

  1. src/node/desktop/src/renderer/desktop-bridge.ts:597-604 — setViewerUrl calls callback() in both .then() and .catch(). If the .then callback throws synchronously, the rejection flows into .catch, which invokes callback() a second time, re-running the deferred navigation. This also diverges from the sibling prepareForSatelliteWindow (:310) and prepareForNamedWindow (:322), which only call callback() in .then. Fix: chain .catch before .then so the callback fires exactly once while preserving best-effort navigation:

    ipcRenderer
      .invoke('desktop_set_viewer_url', url)
      .catch((error) => reportIpcError('desktop_set_viewer_url', error))
      .then(() => callback());

Suggestions

  1. src/node/desktop/src/renderer/desktop-bridge.ts:601-603 — calling callback() after an IPC error navigates the iframe anyway, which can re-surface the exact e2e: cross-origin SecurityError accessing HTML preview iframe on Electron CI (markdown + R Notebook) #17982 SecurityError on the error path. The choice is defensible (a blank pane is worse), but add a why: comment noting this is a deliberate best-effort fallback so the SecurityError can be correlated with the logged IpcError.

  2. src/node/desktop/src/main/desktop-browser-window.ts:540-547 — setViewerUrl returns with no log when !isLocalUrl(url). This is pre-existing, but the change shifts the method's contract from fire-and-forget to "the renderer awaits this for navigation safety": a non-local URL now resolves as success while skipping authority registration, so the iframe navigates to an unregistered authority. Add a logger().logDebug(...) on that branch to make the skip visible.

  3. e2e/rstudio/tests/panes/editor/rnotebook.test.ts:76 — removing test.fixme(...) left a stray blank line between the // Original: comment and const fileName; markdown.test.ts removed its marker cleanly. Delete the blank line for consistency.

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
404 0 16 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · macos-26 ARM64 · commit c4bc9f18184f0caca78dbc9ef727e3ccef3be923 · Run #187

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

🪟 Windows Desktop E2E · Server 2025 x64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
411 0 11 0
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · Windows Server 2025 x64 · commit c4bc9f18184f0caca78dbc9ef727e3ccef3be923 · Run #187

@kevinushey
kevinushey merged commit 8fa205c into main Jun 25, 2026
15 checks passed
@kevinushey
kevinushey deleted the feature/fix-viewer-pane-race-condition branch June 25, 2026 22:19
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.

e2e: cross-origin SecurityError accessing HTML preview iframe on Electron CI (markdown + R Notebook)

2 participants