Skip to content

feat(browser): a page's window.close() closes its tab - #27194

Closed
Hotragn wants to merge 3 commits into
stablyai:mainfrom
Hotragn:feat/browser-window-close-closes-tab
Closed

Hotragn wants to merge 3 commits into
stablyai:mainfrom
Hotragn:feat/browser-window-close-closes-tab

Conversation

@Hotragn

@Hotragn Hotragn commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

ELI5

Some pages close themselves when they are done: "you can close this window" login pages, review tools like Plannotator, confirm pages. In Orca's browser that does nothing today, so these tabs pile up. With this change, when a page calls window.close(), Orca closes that tab for it, the same as clicking the tab's ×.

What Changed

  • Before: the guest preload replaces window.close with a function that does nothing. That guard came from fix(browser): prevent window.close guest crashes #11910 and fix(browser): remove unsafe window close bypass #12040: the native close destroyed the guest under Orca, which crashed main or left a dead tab. So today the call is silently dropped.
  • After: the preload still replaces window.close, so the native close still never runs. Instead of doing nothing, the replacement sends one message to the Orca window with ipcRenderer.sendToHost. The renderer hears it on the <webview> (ipc-message) and closes the page through the normal close path:
    • if the tab has other pages, only that page closes (closeBrowserPage);
    • otherwise the tab closes through closeWorkspaceBrowserTab, the same call the × button makes, so webview cleanup and reopen-closed-tab work the same way.
  • Which closes are allowed: I followed Chrome's rule for tabs that no script opened. A page can close itself only while its tab has one history entry, so a site you browsed to can't close your tab. Orca tabs never have a script opener, because a window.open is re-created as a fresh tab. Pinned tabs stay open, and a page never raises the pin confirm dialog. Pages served by a remote runtime are left alone, the same as the open-link handler does.
  • The listener is added once, when the webview is created, not with the listeners that are removed when the pane unmounts. That way a page in a background tab can close too.

Why

The issue asks whether the blocked close can be routed into Orca's own tab close without undoing the guard. This does exactly that. The page only asks; Orca does the closing.

Alternatives I looked at:

The function I pass into the page world is proxied by contextBridge, so the page gets no new global and no ipcRenderer. It can only trigger the same close it could already ask for.

One gap, on purpose: in Chrome, a tab opened by window.open may close itself even after it navigates. Orca doesn't record which tabs a script opened, so such a tab closes here only while it is still on its first entry. I can follow up if maintainers want that.

Linked Issue

Fixes #26939

Visual Proof

Both screenshots come from the new e2e spec, which runs the real app in the background. The terminal area is masked.

  1. The "Close fixture" tab is open, just before its page calls window.close(). On main the window still looks like this after the call; the first e2e case fails there for exactly that reason.
  1. With this branch, right after the call: the tab is gone and Orca falls back to Terminal 1, as it does for ×.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New e2e tests/e2e/browser-window-close.spec.ts, running the real app in the background. It has two cases:

    • a page calling window.close() removes its tab from both the browser store and the tab strip;
    • a page that navigated first keeps its tab.
  • I ran the e2e spec against main with only the spec added: the first case fails there, because the tab stays open.

  • Unit tests:

    • the preload: the close request is non-replaceable, and the history rule holds;
    • closeBrowserPageFromGuest: last page, sibling page, pinned, remote runtime, and missing page;
    • the webview: only the close channel triggers a close.
  • I loaded the built out/main/browser-window-close-preload.js into a hidden Electron 43.7.5 webview. A fresh page reaches the host's ipc-message, a navigated page does not, and neither fires the native close or destroyed.

  • I checked that the built preload is still one standalone file with no shared chunk, since sandboxed preloads can't load chunks.

  • pnpm typecheck, electron-vite build, oxlint/oxfmt and pnpm run check:code-quality:changed pass. I ran the neighboring browser, window and preload suites rather than the whole pnpm test. The only failures were browser-manager-tab-identity and browser-manager-viewport-ownership, which fail the same way on main on my machine. Tested on macOS.

AI Disclosure

I used Claude Code (Claude Opus 5.5) to help me trace the old window.close guard and the tab close paths, and to draft the change and tests. I checked the design against Electron 43 myself with the probe above, ran the tests, and reviewed every line.

Review

My review of the change, with the agent's help:

  • Cross-platform: no OS-specific code. sendToHost and webview ipc-message behave the same on macOS, Linux and Windows.
  • SSH / remote: pages owned by a remote runtime are skipped, so a page can't close a tab another host owns.
  • Agents / integrations: no agent code touched. Tools that open a page for an agent (for example Plannotator) can now close it.
  • Performance: one listener per webview, and no work unless a page calls window.close().
  • UI: no new UI. A tab closes exactly as it would from ×.
  • Security:
    • the native close still never runs, and the page gains no new global;
    • only the main frame's preload sends;
    • the host acts on one fixed channel and only for its own page id;
    • the worst a page can do is close its own unpinned, single-entry tab.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Mobile and paired clients are unchanged: the remote-runtime webview path is not touched.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

The guest preload turned window.close() into a no-op so a page could never
destroy its own guest (stablyai#11910, stablyai#12040). It now hands the call to the host
page instead, and the renderer closes the page through the same path as the
tab's close button, so the native close still never runs.

Like Chrome, a page can only close a tab that holds a single history entry,
and pinned tabs stay open.

Fixes stablyai#26939
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 37cfb969-5426-45ce-9a9a-88df5a55fd1c
📥 Commits

Reviewing files that changed from the base of the PR and between b48c342 and 79ea87f.

📒 Files selected for processing (1)
  • tests/e2e/browser-window-close.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

The preload routes eligible window.close() calls to the host through IPC. The renderer handles the guest close channel and checks page existence, runtime ownership, workspace page count, and pinned-tab status before closing a page or browser tab. Unit and end-to-end tests cover these rules and behavior after page history changes.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 79ea8

No actionable issue remains from this review; the change is mergeable after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: a page calling window.close() closes its browser tab.
Description check Passed The description is detailed and covers the required sections, including the user impact, implementation, rationale, linked issue, testing, security, compatibility, and checklist. It also documents tha…
Linked Issues check Passed Issue #26939 requests that a page calling window.close() closes through Orca's normal tab-close behavior. The preload keeps the native-close guard and sends a fixed host request for single-entry pag…
Out of Scope Changes check Passed The changed preload, shared channel, webview listener, close helper, and tests directly implement or verify issue #26939. The native-close guard, single-history-entry rule, pinned-tab handling, remote…
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e3af88a2-97ef-4ea6-bee9-3142a0decb1b
📥 Commits

Reviewing files that changed from the base of the PR and between cb69d52 and b48c342.

📒 Files selected for processing (9)
  • src/preload/browser-window-close-installation.ts
  • src/preload/browser-window-close.test.ts
  • src/preload/browser-window-close.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-webview.test.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-webview.ts
  • src/renderer/src/lib/browser-page-guest-close.test.ts
  • src/renderer/src/lib/browser-page-guest-close.ts
  • src/shared/browser-guest-window-close.ts
  • tests/e2e/browser-window-close.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread tests/e2e/browser-window-close.spec.ts Resolved
Comment thread tests/e2e/browser-window-close.spec.ts Resolved
…-close-closes-tab

# Conflicts:
#	src/renderer/src/components/browser-pane/host-guest/browser-page-webview.ts
@Hotragn

Hotragn commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing since #31844 shipped window.close() support, including the opened-by-page case I left out here. Thanks @AmoabaKelvin.

@Hotragn Hotragn closed this Oct 26, 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.

[Feature]: Close the tab when a page in the embedded browser calls window.close()

1 participant