sendToActiveTab function exported ✓ 85.7%
Last updated: 2026-02-24T21:07:57.586Z
Metrics
LOC: 20
Complexity: 4
Params: 3
Coverage: 85.7% (6/7 lines, 3x executed)
Signature
sendToActiveTab(
message: ExtensionMessage,
options: ActiveTabMessageOptions = {},
): : Promise<unknown>
Summary
Sends a message to the currently active tab. Optionally injects the content script if it’s not yet loaded.
Source Code
export async function sendToActiveTab(
message: ExtensionMessage,
options: ActiveTabMessageOptions = {},
): Promise<unknown> {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (!tab?.id) return { error: "No active tab" };
if (!options.injectIfNeeded) {
return sendToTab(tab.id, tab.url, message);
}
try {
return await sendToTabWithInjection(tab.id, tab.url, message);
} catch (initialError) {
return {
error: "Content script not responding",
details: String(initialError),
};
}
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| sendToTab | calls |
| sendToTabWithInjection | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| handleMessage | uses |
| sendToActiveTab | uses |
| render | uses |