惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
U
Unit 42
Vercel News
Vercel News
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
C
Check Point Blog
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
博客园_首页
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
Last Week in AI
Last Week in AI
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
V
Visual Studio Blog
小众软件
小众软件

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Built the Chrome Feature Google Never Shipped
Muhammad Ali · 2026-05-16 · via DEV Community

From 24 tabs of chaos to a single saved card restored exactly where you left off.# I Built the Chrome Feature Google Never Shipped


Tags: chrome productivity javascript webdev
Cover image: [use cover.svg or a screenshot of the extension UI]


There's a moment every developer knows.

You're deep in it. Twelve tabs open. GitHub PR on the left, Stack Overflow thread you've been nursing for an hour, local dev server, three docs pages, a Figma file someone dropped in Slack. You're finally in flow.

Then something pulls you away. A meeting. A call. Another project that's suddenly on fire.

You come back. And it's gone. Not just the tabs the context. The mental thread you'd been holding for the last two hours. You spend the next fifteen minutes just getting back to where you were.

I got tired of losing that time. So I built something.


What I Built

Context Switcher is a Chrome extension that gives your browser a Save Game button.

  • Freeze — saves every open tab, its scroll position, pinned state, and title into a named workspace snapshot
  • Thaw — opens a new window and restores everything exactly as you left it, including scroll positions
  • Rename / Delete — manage your saved workspaces from the popup

All data is stored locally via chrome.storage.local. No server. No account. No cloud.


The Technical Problem That Made This Interesting

The obvious approach doesn't work.

You can't just save URLs and reopen them. The page loads fresh from the top. Scroll position is gone. For documentation pages, GitHub diffs, long Notion docs that matters a lot.

The solution involves injecting a content script before the tab finishes loading, registering the listener first, then restoring scroll after status === 'complete' fires.

// Register listener BEFORE creating any tabs
// This eliminates the race condition
const listener = (tabId, changeInfo) => {
  if (changeInfo.status === 'complete' && tabId === newTab.id) {
    chrome.tabs.onUpdated.removeListener(listener);

    setTimeout(() => {
      chrome.scripting.executeScript({
        target: { tabId },
        func: (x, y) => window.scrollTo(x, y),
        args: [tab.scrollX, tab.scrollY]
      });
    }, 300); // small delay for JS-heavy pages to settle
  }
};

chrome.tabs.onUpdated.addListener(listener);
const newTab = await chrome.tabs.create({ url: tab.url });

Enter fullscreen mode Exit fullscreen mode

The 300ms delay is intentional. Without it, SPAs and JS-heavy pages scroll to the saved position and then immediately reset as their own JS finishes initializing. Found this the hard way.


The Other Problem — Restricted URLs

Chrome throws an error if you try to inject scripts into:

  • chrome:// pages
  • chrome-extension:// pages
  • The Chrome Web Store itself
  • devtools:// pages

The fix is a simple guard before every script injection:

const RESTRICTED = [
  'chrome://', 'chrome-extension://',
  'devtools://', 'https://chrome.google.com/webstore'
];

function isRestricted(url) {
  return !url || RESTRICTED.some(prefix => url.startsWith(prefix));
}

Enter fullscreen mode Exit fullscreen mode

Restricted tabs are saved as-is (URL + title) but scroll restore is skipped gracefully. No crashes, no error popups.


Architecture in Brief

manifest.json          ← MV3, service worker, permissions
background.js          ← handles FREEZE / THAW / DELETE / RENAME
content/capture.js     ← injected at freeze time, returns scroll + form data
popup/popup.html|js    ← the UI, sends messages to background
utils/storage.js       ← chrome.storage.local CRUD helpers

Enter fullscreen mode Exit fullscreen mode

One thing worth knowing about Manifest V3 service workers: they can be killed by Chrome at any time when idle. If you're holding state in memory and the worker goes to sleep, that state is gone when it wakes up. Everything in this extension is persisted to chrome.storage.local immediately — nothing lives only in memory.


What I Skipped in v1 (and Why)

Form data restoration — capture works, but restoring values into <input> fields on an already-loaded page is unreliable across different frameworks. React-controlled inputs especially fight you. Punted to v1.1.

Tab group preservation — the tabGroups API exists but group IDs are ephemeral. You can't save a group ID and restore it later. Would need to recreate groups by name, which feels fragile. Still thinking about the right approach.

Favicon cachingfavIconUrl URLs expire after the browser session. Storing them as base64 data URIs at freeze time would fix this but bloats storage. Left it for now.


What I'd Do Differently

One thing I underestimated: how much time the UX takes compared to the logic. The background script was done in a day. Getting the popup to feel right loading states, rename inline editing, delete confirmation, empty state took three times as long.

If you're building a Chrome extension for the first time, budget more time for the popup than you think you need. It's not just a form. It's the entire user experience.


Try It

Context Switcher is free on the Chrome Web Store.

If you're the type who has seventeen tabs open right now, it might be useful.

Happy to answer questions about the architecture, the MV3 gotchas, or anything else in the comments.


Add Context Swither: [https://chromewebstore.google.com/detail/context-switcher/jhclcpgoodoieodcmklijelcggeknfej]