Chrome lets you save a tab group. Close it, reopen it later, and every tab comes back on the right page. Press Back, though, and nothing happens: Chrome saved where each tab is, not where it had been.
I wanted the whole thing back, so I built Back Pocket, a Chrome extension that saves tab groups with each tab's Back history. The hard part wasn't saving the history. It was giving it back.
Recording where a tab has been
An extension can't read a tab's Back list directly. There are two ways to get it:
- Follow it as it happens.
chrome.webNavigationreports every top-frame navigation:onCommittedfor ordinary ones,onHistoryStateUpdatedforpushState,onReferenceFragmentUpdatedfor#anchors. The transition type and qualifiers say whether the user went forward, back, or replaced the page, so the extension can keep its own copy of the list, up to 50 entries, the most Chrome keeps per tab. It runs quietly, with nothing shown to the user. - Ask through the debugger. For a tab that was already browsing before the extension started following it,
chrome.debuggercan attach and callPage.getNavigationHistory. That works, but Chrome shows its "started debugging this browser" bar while it does, so it's the fallback, not the default.
Giving it back
Here's the catch: there is no API to set a tab's history. The only way to give a tab a Back list is to walk it through the pages in order.
My first attempt used chrome.tabs.update for each step. The pages loaded, the URLs were right, and Back skipped every one of them. Chrome treats a navigation nobody asked for as something the Back button should pass over.
What finally worked:
- Wait for the tab's first page to commit.
- Attach the debugger. For each later page, run an empty script as a user gesture (
Runtime.evaluatewithuserGesture: true), thenPage.navigateto the page, and wait for the commit. - Step back to the page the tab should show (
Page.getNavigationHistory, thenPage.navigateToHistoryEntry) and detach.
The empty gesture is the whole trick. Measured on Chrome 154: without it, Back found no page; with it, Back stops at every one. Every page in the trail really loads, so a long trail takes a few seconds, which is why it's a separate "Restore with history" action and plain Restore stays instant.
Not paying for it in memory
Restoring a 30-tab group shouldn't load 30 pages. Restored tabs open as a tiny placeholder page that shows the title and swaps in the real page the first time you look at it. If the tab has a history, that's when the rebuild runs.
What I'd tell anyone building something similar
- Measure what Chrome actually does. The docs don't say that gesture-less navigations are skipped by Back; the test did.
- Keep the debugger as a fallback. Users notice that bar, so follow navigations when you can.
- Two things must never attach the debugger to the same tab at once: whichever comes second fails.
Back Pocket is free on the Chrome Web Store: https://chromewebstore.google.com/detail/hpihlojfcfnmcnaafeepfdgbfjoipfkb. If you know a cleaner way to hand a tab its history, I'd genuinely like to hear it.
