Full Stack & AI Engineer Guide: Chrome Extensions (Manifest V3) & AI Side Panels
Browser extensions are the most direct distribution surface for B2B workflow automation, CRM enrichment overlays, and context-aware AI copilots. However, Google's transition to Manifest V3 (MV3) fundamentally changed extension architecture: persistent background pages are gone, remotely hosted code execution is strictly banned, and ephemeral Service Workers terminate after 30 seconds of inactivity. As a Senior Full Stack Engineer and AI Application Engineer, I build production React + TypeScript Chrome Extensions that pass Chrome Web Store security reviews on the first submission.
1. Surviving Ephemeral Service Workers in Manifest V3
In Manifest V2, developers stored authentication tokens and WebSocket connections inside global JavaScript variables in a persistent background page. In Manifest V3, Chrome unloads the background Service Worker whenever idle—wiping all in-memory globals. Production MV3 extensions must adhere to three architectural rules:
- Top-Level Event Listener Registration: Always register
chrome.runtime.onMessage,chrome.alarms.onAlarm, andchrome.commands.onCommandsynchronously at the top level ofbackground.tsso Chrome can wake the worker reliably. - State Persistence in
chrome.storage.session&chrome.storage.local: Persist in-flight state in encrypted session/local storage rather than module-scoped variables. - Streaming AI Responses via Long-Lived Ports (
chrome.runtime.connect): Single-shotsendMessagecalls time out or lose context during multi-second LLM token streaming. Using named ports keeps the Service Worker active while streaming Server-Sent Events (SSE) from your backend to the Side Panel or Content Script.
// src/background/serviceWorker.ts (Manifest V3)
chrome.sidePanel
.setPanelBehavior({ openPanelOnActionClick: true })
.catch((err) => console.error("SidePanel config error:", err));
chrome.runtime.onConnect.addListener((port) => {
if (port.name !== "ai-copilot-stream") return;
let abortController: AbortController | null = null;
port.onMessage.addListener(async (msg: { action: string; pageContext: string }) => {
if (msg.action !== "STREAM_SUMMARY") return;
abortController = new AbortController();
try {
const { authToken } = await chrome.storage.session.get("authToken");
const response = await fetch("https://api.example.com/v1/agent/stream", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${authToken || ""}`,
},
body: JSON.stringify({ context: msg.pageContext }),
signal: abortController.signal,
});
if (!response.body) throw new Error("Empty stream body");
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
port.postMessage({ type: "CHUNK", delta: decoder.decode(value, { stream: true }) });
}
port.postMessage({ type: "DONE" });
} catch (err) {
port.postMessage({ type: "ERROR", message: (err as Error).message });
}
});
port.onDisconnect.addListener(() => {
abortController?.abort();
});
});
2. Style-Isolated UI Injection with Shadow DOM & chrome.sidePanel
Injecting React components directly into third-party host pages (like Gmail, LinkedIn, or Salesforce) causes host CSS rules to break your extension's typography and layout. By mounting React roots inside an isolated attachShadow({ mode: "open" }) container with scoped stylesheets—or utilizing Chrome's native chrome.sidePanel API—your extension UI remains 100% immune to host-page CSS collisions.
3. Hire a Senior Full Stack & AI Engineer for Chrome Extensions
Need to build a Manifest V3 Chrome Extension, AI browser copilot, or migrate a legacy MV2 add-on? Explore my Full Stack Engineer Guide, review my AI Application Engineer Guide, or book a 1-Day Extension Architecture Sprint.