GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(browser): open a middle-clicked link in a new tab by Hona · Pull Request #65091 · anomalyco/opencode Conversation
|
| Before | After |
|---|---|
![]() |
![]() |
Ctrl+Shift+click opens it in front: ![]() |
Pictures were taken from the pane's component fixture (real side region, pane and model) with a throwaway fake main on a made-up page; that fake main is not part of this PR. "Before" is the same setup with dev's rule.
setWindowOpenHandler allowed every web destination. Since it, a request opens only when CDP's Page.windowOpen reported it with userGesture: popupActivated(popupReport, url) at packages/gui-plugins/src/browser/chromium.ts:891 on dev, refused at :906.window.open and target="_blank". A link it routes to a new tab by the click's button and modifiers goes through OpenURL and has no report (measured in Electron 44.9.1: disposition: "background-tab", no Page.windowOpen). So every such click was a pop-up without a gesture.windowOpening in the new window-open.ts owns the decision.
window.open or target="_blank" (Page.windowOpen) is decided by that report's userGesture alone, as on dev.Page.frameRequestedNavigation, reason anchorClick). window.open never has one.activityOwner), and their latest input is a press of the left or middle button, or Enter, within Chromium's activation lifetime. Any request uses the press up.background-tab opens, because Chromium gives it only while it handles a real press with the middle button or Ctrl/Cmd; foreground-tab and new-window, which a made-up click can ask for, open only the link under the pointer (update-target-url).Why this does not rest on timing:
window.open whose own report were lost has no anchorClick report, so a press gives it nothing.Page.windowOpen and Page.frameRequestedNavigation before it sends CreateNewWindow or OpenURL, all on the frame's channel-associated pipe, and Electron emits the event synchronously. Measured in Electron 44.9.1 with the CPU throttled 6x, busy loops and a spinning worker: 2,200 of 2,200 window.open requests had their report when the handler ran.window.open in a timer 50 ms after a click in the same frame is reported with userGesture: true and opens, as on dev and in Chrome. What stays blocked is what Chromium reports without a gesture, and a link click the page makes up.flowchart TD
R[page asks for a tab] --> A{artifact?}
A -- yes --> ASK[offer the link in a notice]
A -- no --> O{a tab can show it?}
O -- no --> REF[answer as a click on that link]
O -- yes --> P{Page.windowOpen report?}
P -- yes --> G{userGesture, same address}
P -- no --> L{anchorClick report for this address?}
L -- no --> B[Pop-up blocked]
L -- yes --> U{person's unused press, and its disposition?}
G -- no --> B
U -- no --> B
G -- yes --> T[new tab: behind for background-tab, else in front]
U -- yes --> T
| The person does | Chrome | This pane |
|---|---|---|
| Middle-click, Ctrl/Cmd+click, Ctrl/Cmd+Enter on a link | New tab behind, next to the opener, no window.opener even with rel="opener" |
Same, but at the end of the strip |
| Ctrl/Cmd+Shift+click, Shift+middle-click | New tab in front | Same |
| Shift+click | New window | New tab in front (the pane has no windows) |
Click a target="_blank" link, or window.open from a click |
New tab in front | Unchanged: same |
window.open with no gesture |
Blocked | Unchanged: blocked, same notice |
| A modified link click the page makes up within 5 s of a real press | Opens (user activation) | Blocked, same notice, as on dev |
Middle-click on no link, or on a javascript: link |
No request | Nothing, no notice |
| Middle-click a mail or app link | No tab | The offer a click on it gets |
| A new tab whose first navigation becomes a download | The tab closes once the download has its place; in front, the opener is selected again | Same |
| A new tab whose first navigation redirects to a mail or app link | The tab closes after the app is launched | The tab closes, and the tab it was opened from gets the offer a click gets |
| A new tab whose first navigation redirects to a refused address | Error page in the tab | The tab stays on the new-tab view with the pane's refusal notice |
Sources: DispositionFromClick, NavigationPolicyFromEvent (a background tab needs a real input event), ShouldBlockPopup called from Browser::OpenURLFromTab, kActivationLifespan, DetermineInsertionIndex, InspectorPageAgent::WindowOpen and FrameRequestedNavigation (flushed before CreateNewWindow and BeginNavigation, on the pipe of FrameHost), NavigationPolicyForCreateWindow, Electron's OpenURLFromTab, DownloadUIController::OnDownloadUpdated and LaunchUrlWithoutSecurityCheckWithDelegate (a new tab left with nothing to show closes), and Chrome's mouse shortcuts, which list the modified clicks but not the middle button.
A tab closes this way only when a page opened it, it has shown no document, and it is the person's (closesUnshown). A tab that had committed a page stays.
policy.ts are untouched. Its click on a target="_blank" link still opens its tab, and its new tab keeps its download and stays.window.open on load or a timer, and a modified click the page makes up, stay blocked with the same notice.target="_blank" tab: partition, session guard, URL policy, blocker wait, saved tabs and history.window-open.test.ts: both rules as tables, person and agent, web page, preview, extension page and artifact.electron-links.test.ts: real Electron through electron-run.ts, hidden window, Chromium input events. Fails on dev with the pop-up notice. Downloads get their save path in the fixture's own will-download listener before the page's handler runs, so no save dialog can open; the download ends after its tab has closed.window.open from a frame the press gave no activation, and a Shift+click the page makes up, after a press elsewhere and after a press on a link whose navigation the page prevents. 12 cases, all blocked with the notice.pane-machine.test.ts: a tab closed in front selects its opener; behind, the selection stays.Layout.open), so the tab lands at the end, not next to its opener.pane.ts that close the tab and pass the opener's notice are covered by the page-level test and the machine test, not end to end.No feature flag: this is a fix.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The decision logic matches the description, and it follows Chromium's rule for whether a link opens or counts as a blocked pop-up. I checked the rule table in window-open.test.ts (passes) and tsc -b (clean). I couldn't run the real-Electron test: Electron won't start in this container because a system library is missing. So the fix itself is not verified here. The before/after images in the description show the desktop change.
Public API: unchanged. PageMenuHost.open gains an optional background argument, but that type is internal to the plugin.
Two things worth a look (inline):
Page.windowOpen report, the rule now allows the request after a recent press, where before it blocked it. If that report can ever arrive after the window-open handler runs, a window.open without a gesture made soon after a click or key press would now open.windowOpening itself, so it adds little beyond the Electron test.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| if (!request.openable) return { type: "refuse" } | ||
|
|
||
| const activated = request.report |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
When there's no report, a press in the last 5 s is now enough to open. Before, this path blocked. That's correct for a link Chromium routes by its click. But if Page.windowOpen (a CDP event from the renderer) can ever arrive after setWindowOpenHandler runs, a window.open without a gesture made shortly after any click or key press would now open: the base blocked it, and this opens it. Is that ordering guaranteed? If not, could the press path be limited to requests that can't come from window.open, or could the handler wait briefly for the report? The timer/synthetic cases in electron-links.test.ts run with no press before them, so they don't cover this.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The order holds for window.open (Blink flushes Page.windowOpen before the sync CreateNewWindow on the same channel pipe; 2,200 of 2,200 reports came first with the CPU throttled 6x), but the press path no longer rests on it: it now also needs Chromium's anchorClick navigation report for the same address, which window.open never has, and the press's own disposition, so a missing or late report only blocks. electron-links.test.ts now presses first and lets the page ask 50 ms, 500 ms and 2 s later (12 cases, renderer throttled 4x, 30 runs), and the Shift+click it makes up, which the old rule opened, is blocked.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'm satisfied this resolves the concern. In pr/head (2450d30), a late or missing Page.windowOpen report can no longer make a no-gesture window.open open.
linkPressed (window-open.ts) returns false unless request.link?.url === request.url. link is only ever set from Page.frameRequestedNavigation with reason === "anchorClick" and a newTab/newWindow disposition (chromium.ts:601-602), and window.open never produces that report. A window.open whose own report was lost is therefore blocked, even right after a press.background-tab opens. foreground-tab and new-window open only for the link under the pointer (hovered, from update-target-url). This is what closes the case of a Shift+click the page makes up on another link.popupReport, linkReport and press, whether it opened or not (chromium.ts:1001-1004). A new mouse-down also clears press, as does any key other than Enter. An agent press never sets press.electron-links.test.ts:104-112 now presses first, either elsewhere on the page or on a link whose navigation the page prevents. 50 ms, 500 ms and 2 s later, a frame window.open and a made-up Shift+click are both expected to be blocked: 2 × 2 × 3 = 12 cases.What I checked: I read window-open.ts, the handler and event wiring in chromium.ts, and the test at pr/head. bun test src/browser/window-open passes (50/50). I couldn't run electron-links.test.ts here because Electron fails to start (libnspr4.so is missing in this container). So I haven't confirmed the 12 cases, the 30-run result, or the 2,200/2,200 ordering measurement.
I didn't change anything. I used a temporary worktree in /tmp/opencode and removed it. repo/ is still on its older HEAD, with the existing bun.lock change left in place.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // new tab in its inventory, selected only when it opens in front, or the pop-up notice. | ||
| const linked: Browser.Tab[] = [] | ||
|
|
||
| const openLink = (event: MouseEvent) => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This fake main runs windowOpening itself with report: undefined and pressedAt === at, so it can only answer "open". What the story really tests is the pane getting a state event that doesn't change the selection, which the target="_blank" path already covers. electron-links.test.ts is the test of the fix. I'd drop this handler and the new story in browser-pane-restore.spec.ts to keep the change smaller.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Dropped: the fake-main handler and both new stories are gone, so panel.fixture.tsx and browser-pane-restore.spec.ts are the same as on dev. electron-links.test.ts is the test of the fix, and pane-machine.test.ts holds the selection after a tab closes itself.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. On pr/head, git diff pr/base pr/head shows no changes to panel.fixture.tsx or browser-pane-restore.spec.ts, so both match dev again. The fixture no longer has the fake-main handler, which could only ever answer "open".
electron-links.test.ts and window-open.test.ts.pane-machine.test.ts case (lines 430–447) covers what the dropped story only touched. It checks that a tab closing itself returns focus to its opener only when it was in front. When it was behind, the selection stays put and no focus is emitted. When the opener is gone, focus goes to the first tab.bun test src/browser/pane-machine.test.ts src/browser/window-open.test.ts passes: 60 tests, 0 failures.electron-links.test.ts (it needs Electron) or the component specs.I made no changes. bun.lock shows as modified in the shared checkout; that isn't from me, and I left it alone.
Nothing more to do in this thread.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The new commits look sound. The tab-closing logic only closes a tab a page opened, that has shown no document and is the person's. For a download it waits until the download has its save path or has ended. The opener gets the offer for a mail or app link, and the opener is selected again only when the closed tab was in front. I ran window-open.test.ts and pane-machine.test.ts (60 pass) and tsc -b (clean). I still couldn't run the real-Electron test here (libnspr4.so is missing), so the fix itself isn't verified.
Public API: unchanged. tab.closed gains an optional opener and the popup callback gains a refused argument, but both are internal to the plugin.
Neither earlier point is addressed yet: the press-only fallback when there's no Page.windowOpen report, and the fake-main handler in panel.fixture.tsx. Both threads stay open.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
# Conflicts: # packages/gui-plugins/src/browser/chromium.ts
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Both earlier points are addressed.
Page.windowOpen report now needs Chromium's anchorClick navigation report for the same address, as well as the person's unused press. A late or missing report now blocks instead of opening.The new rule looks sound. I ran window-open.test.ts and pane-machine.test.ts (76 pass) and tsc -b (clean). I still couldn't run the real-Electron test here (Electron won't start in this container), so the fix itself isn't verified by me.
Public API: unchanged.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.