Skip to content

feat(browser): open a link's new tab beside the tab it came from - #65126

Merged
Hona merged 10 commits into
devfrom
browser-tab-position
Nov 20, 2026
Merged

Hona merged 10 commits into
devfrom
browser-tab-position

Conversation

@Hona

@Hona Hona commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

A tab a page or link opens in the browser pane now appears beside the tab it came from, as in Chrome. Before, it was added at the end of the side strip, after every file, review and browser tab. It appears at the click and changes its label once, from "New tab" to the page's title. Follow-up to #65091.

Before After
The new tab at the end of the strip The new tab beside the tab it came from

Pictures were taken from the pane's component fixture (real side region, pane and model, main's events sent through the Ipc schema, the fixture's plain strip given borders) on a made-up page, after the real sequence below.

Chrome's rule

All in tab_strip_model.cc at Chromium 152 (tab_strip_model_order_controller no longer exists; its logic lives there).

Case Chrome Source
A link opens a tab behind (middle-click, Ctrl/Cmd+click) After the last tab the opener already opened, counting tabs those opened, while they stand in a row to its right; else right after the opener DetermineInsertionIndex, GetIndexOfLastWebContentsOpenedBy
A link opens a tab in front (target="_blank", window.open from a click, Ctrl/Cmd+Shift+click, Shift+click) Right after the opener, before any opened behind; every earlier opener is forgotten DetermineInsertionIndex, InsertTabAtImpl
"+" or the new-tab shortcut End of the strip DetermineInsertionIndex
The person selects another tab Openers are forgotten only when they leave a tab that was opened for an unrelated one. Opener to child, child to opener, sibling to sibling, and the opener to an unrelated tab and back all keep the row OnActiveTabChanged
An address is typed into a tab Openers are forgotten, except for the first address typed into a new tab at the end (a quick look-up) TabNavigating
A tab closes What it opened counts as opened by its own opener FixOpeners

From click to loaded

Measured in Electron 44.9.1 on a page with 800 ms to first byte and its <title> 400 ms later:

dev Now
Opened behind At the end. "New tab" at 5 ms, its address at 810 ms, its title at 1,212 ms Beside its opener. "New tab" at 5 ms, its title at 1,212 ms
Opened in front At the end, selected at once over the pane's new-tab state, relabelled twice Beside its opener, selected at once over the same state, relabelled once
A document with no <title> "New tab", then Chromium's name at the commit "New tab", then Chromium's name when its load ends
A load that fails "New tab", then its address "New tab", then its address once, with its error page

What the strip does at each step (getBoundingClientRect() of every tab in the component stories, on the fixture's strip with an 8 px gap; the same in front and behind):

Step Label Tabs left of it Tabs right of it Its width
Click: the tab is listed, and selected when it opens in front New tab 0 px +97.17 px (its width and the gap) 89.17 px
Load starts New tab 0 px 0 px same
Document commits under Chromium's name, its address New tab 0 px 0 px same
Document names itself One 0 px −25.88 px (the labels' difference) 63.30 px
Icon arrives One 0 px 0 px same
Load ends One 0 px 0 px same

Two tabs opened behind and named in reverse order: each appears at its click in the order opened, and each naming moves only the tabs to its right.

How it is built

flowchart LR
  P[page or link opens a tab] --> M["pane-machine.ts: tab.opened with beside"]
  M -->|"tab-openers.ts: placedAfter"| I[inventory lists it after that tab, at once]
  I -->|"state event: placed { tabID, after }, unnamed [...]"| W["window machine: sync-strip"]
  W -->|"layout.open(key, session, { tab: 'append', after })"| H[host strip: appendSessionTab]
Loading
  • Main owns the rule. The pane machine keeps Chrome's openers (tab-openers.ts) and inserts the tab into its inventory, so the saved order and the agent's tabs.list agree with the strip.
  • The window only adds. The strip holds other panels' tabs too, so main says once, with the inventory that first lists the tab, which tab it stands after. A tab the strip already has never moves.
  • One relabel. Main lists the tabs a link opened whose first page has no name of its own yet (unnamed), and the strip draws those as "New tab". A tab leaves the list when its document names itself or its load ends (named in pane-machine.ts):
function named(before: Browser.Tab, tab: Browser.Tab) {
  const blank = tab.url === "about:blank"

  if (!tab.loading) return (before.loading || before.loadError !== undefined) && (blank || tab.title !== "")

  return !blank && tab.generation === before.generation && tab.title !== "" && tab.title !== before.title
}
  • Host change, built-ins only. BuiltinLayout.open takes after (BuiltinOpenOptions in @opencode/plugin/gui/builtin), and the host's appendSessionTab places the key after it. No public plugin API changed: Layout and OpenOptions are untouched. The host names no plugin.

Which tabs

  • Beside the opener: a tab a page opened (the cases above), and a tab a page's own link opened through the page menu's "Open link in new tab", the pop-up notice's Open, or a link in a workspace preview. Chrome places its context menu's "Open link in new tab" the same way: it is a link transition into a background tab (render_view_context_menu.cc).
  • Agent: unchanged from dev. Its tabs.open and the pop-ups of a page it drives are listed at once, at the end, with their activity mark.
  • End of the strip, as before: "+", chat links, the file tree, previews and artifacts opened from the conversation, extensions' chrome.tabs.create.
  • Restart: the host stores the strip's order and the saved tabs carry the labels, so the strip draws the same order at once, and main's restored inventory moves nothing.

Tests

  • pane-machine.test.ts: two tables of event sequences that replay what a page reports. When a tab is listed and how long it keeps its new-tab label (13 rows: behind and in front; untitled, failed and refused loads; two named in reverse order) and where it stands (10 rows: each row of the Chrome table).
  • electron-links.test.ts: a middle-click on a link to a slow page in real Electron, with the page's reports fed to the pane machine. The window is told of the tab at the click, after the pressed tab, and its label changes once.
  • session-tabs.test.ts: the host's placement. machine.test.ts: the window places a new tab and keeps its new-tab label until main names it.
  • browser-pane-restore.spec.ts: two stories on the strip with three browser tabs, measuring every tab's box at every step of the table above: one tab behind, then two behind named in reverse order, then quit and reopen; and one tab in front. Drawing the address label at the commit fails both.

Limits

  • Two moves per new tab. The tabs to its right move when it appears and when it takes its title. Chrome's equal-width tabs move for neither.
  • A page that never names itself and never stops loading keeps "New tab" in the strip. The address field shows its address.
  • Other new tabs are unchanged. A tab from "+", a chat link or the agent still shows its address between "New tab" and its title, as on dev.
  • Closing a tab is unchanged and does not match Chrome. Chrome selects a tab the closed tab opened, then its opener's next tab, then the opener, then the right neighbour. The strip selects the left neighbour; only a tab that closes itself returns to its opener.
  • Other panels' tabs. Main does not hear the person select a file or review tab, so that never ends a row. It does not hear a drag either: the new tab follows the tab main names, wherever that stands.
  • A title that changes later (a page that sets document.title, or a navigation) changes the tab's width, as for every tab.
  • The page menu's "Open link in new tab" opens in front here; Chrome opens it behind. Unchanged.
  • Not run end to end: no test attaches a pane to a server, so the two call sites in pane.ts that pass beside are covered by the machine and component tests only. The installed app, macOS and Linux were not run.
  • feat(app): order side tabs by recent activity #60270 and feat(app): add optional server-grouped Side tabs #61287 reorder the shell's session tabs (shell/titlebar), not this strip; nothing here depends on either.

No feature flag: this finishes the Chrome behaviour of #65091 and changes only where a new tab lands and which interim label it skips.

@opencodejr opencodejr 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.

I found no problems that should block this. I read the opener logic against the Chrome cases in the description, and the closest tests pass: 130 in pane-machine.test.ts and machine.test.ts, 25 in session-tabs.test.ts. tsc -b is clean in gui-plugins and app. I could not run the new component spec because Playwright's Chromium isn't installed here, and I couldn't drive the desktop pane, so I haven't seen it work end to end. The before/after pictures in the description stand.

Public API: unchanged. BuiltinOpenOptions.after and the BuiltinLayout.open overload are in the workspace-only @opencode/plugin/gui/builtin, and the placed field on the pane's state event is internal Ipc. The public Layout and OpenOptions are untouched.

One minor gap that doesn't block: when a page opens a tab before the session's location is known (the strip is not located yet), the placed hint is dropped. That tab then falls back to the end of the strip once the location arrives.

@opencodejr opencodejr 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.

I found no bugs in the new commits. I read the new holding step (held, tab.due, list, and the window machine's withheld) and ran the closest tests: pane-machine.test.ts and machine.test.ts give 148 pass. session-tabs.test.ts gives 25 pass, and tsc -b is clean in gui-plugins and app. electron-links.test.ts could not run because Electron can't start in this sandbox. I couldn't drive the desktop pane, so I haven't seen it work end to end. The public API is still unchanged: after and held/placed are in the workspace-only gui/builtin and the internal pane Ipc.

One new concern: a tab a click opens in front can now show nothing for up to 3 s (see the inline comment).

if (!background) dispatchBinding(binding, { type: "tab.focused", tabID: popup.state().id })

return popup.contents
// The person's stands beside this tab, and takes the pane once the strip shows it (`tab.opened`).

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.

When a slow page's link opens a tab in front (target="_blank", Shift+click), the person now sees nothing at all for up to LISTING_DEADLINE_MS (3 s): no tab, no spinner, and the pane stays on the old page. To them the click looks like it did nothing, and they may click again. Chrome shows the new tab straight away and lets it relabel. Holding a background tab back to avoid the width change seems fine, but could a front tab be shown at once, or with a much shorter deadline?

@opencodejr opencodejr 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.

My earlier point is fixed: a tab a link opens is now listed and, when it opens in front, selected straight away. It shows as "New tab" until its page names itself, so the old 3 s period with nothing visible is gone. I found nothing new to raise in this commit.

I checked it by reading the diff and running the closest tests. pane-machine.test.ts and machine.test.ts give 142 pass, and tsc -b is clean in gui-plugins and app. I couldn't run the Electron or Playwright tests or the desktop pane here, so I haven't seen it work end to end.

The public API is unchanged: unnamed and placed are internal pane Ipc fields, and after is in the workspace-only gui/builtin.

@Hona
Hona merged commit 80d7c17 into dev Nov 20, 2026
27 checks passed
@Hona
Hona deleted the browser-tab-position branch November 20, 2026 12:34
huuhabn pushed a commit to huuhabn/opencode that referenced this pull request Nov 20, 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.

1 participant