Quick answer
Most tab-management methods do not require the tabs permission. Creating a tab or querying its identifier differs from reading its sensitive URL, title, pending URL, or favicon. Request tabs, matching host access, or temporary activeTab only when the feature needs the corresponding information or operation.
Bind a user action to the tab selected at invocation. Do not re-query the active tab after a long await and accidentally act on a newly selected page. A tab identifier lasts within a browser session, while its document can change; document-bound results need stronger identity than the tab number alone.
Practical implementation steps
- Identify the API operation rather than granting access to an entire namespace.
tabs.createcan open an extension report withouttabs; reading a website title has sensitive-property access rules. - Choose
currentWindowfrom a popup and considerlastFocusedWindowfor an extension-wide worker command. An active tab is not necessarily in the focused window. Check that a usable integer identifier exists. - Capture the identifier before asynchronous work. If a command mutates a page, use a document or run identifier and verify that the response still belongs to it. Never use the user’s new active tab as a fallback after the original closes.
- Catch rejected API promises. A tab may close, navigate, or become inaccessible between query and operation. Show a recoverable “Open the page and run again” state instead of swallowing failure.
- Treat website URLs as input. A page-supplied link is not authorization to navigate, fetch, or transmit it. Use an allowlist when the feature expects a known destination and render page titles as text.
A Font Picker-style explicit inspection fits an invocation-bound operation. Do not infer its manifest permissions from that product example. Also distinguish screenshot access from DOM injection: captureVisibleTab has documented access rules and can capture some sensitive pages with activeTab even where script injection is restricted.
Implementation example
This extension-page function finds the current tab and sends a bounded request to an already installed content script. Querying the identifier does not itself require tabs; installing the receiving script has its own access requirements.
export async function readSelectionFromCurrentTab() {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (!Number.isInteger(tab?.id) || tab.id < 0) throw new Error("No usable tab");
const tabId = tab.id;
const result = await chrome.tabs.sendMessage(tabId, { type: "selection/read" });
if (typeof result?.text !== "string" || result.text.length > 2000) {
throw new Error("Invalid selection response");
}
return { tabId, text: result.text };
}
The caller must catch a missing receiver or closed-tab rejection and show it in the UI. For a document-sensitive operation, use supported documentId targeting or your own verified run contract rather than presenting this simple tab-only response as navigation-safe.
Tradeoffs and alternatives
Broad tabs access supports genuine tab-management products but exposes sensitive metadata. Temporary activeTab suits explicit one-page work; narrow host access suits automatic work on known sites. Choose from the feature rather than a starter manifest.
Common mistakes
- Adding
tabsbecause anychrome.tabsmethod appears in code. - Re-querying the active tab after a delayed operation.
- Persisting tab IDs as permanent cross-session record identity.
- Treating a captured screenshot as proof of script-injection access.
Production checklist
- Sensitive-property access has a feature reason.
- The chosen tab is captured before awaits.
- Closure, navigation, and missing receivers are handled.
- Document-specific results cannot silently become another page’s result.
- Screenshot and injection access are checked separately.
FAQ
Can a content script call the Tabs API?
No. Use a narrow message to an extension page or worker when necessary.
Why is tab.url missing?
Sensitive-property access may be absent, or the tab may not yet have a committed URL. Do not assume every Tab object has it.
What should I verify next?
Run the operation while switching or closing tabs and confirm that it fails on the original target rather than acting on a replacement.
Primary sources
Related guides and examples
Need this implemented in a real product?
Browser tools with a clear purpose, focused permissions, and a maintainable Manifest V3 architecture.