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)

graph LR sendToActiveTab["sendToActiveTab"] sendToTab["sendToTab"] sendToTabWithInjection["sendToTabWithInjection"] sendToActiveTab -->|calls| sendToTab sendToActiveTab -->|calls| sendToTabWithInjection style sendToActiveTab fill:#dbeafe,stroke:#2563eb,stroke-width:2px click sendToActiveTab "a91f63e9f38af9db.html" click sendToTab "4b0c8d5eae39e1ff.html" click sendToTabWithInjection "c1233e42257a3186.html"
TargetType
sendToTab calls
sendToTabWithInjection calls

Impact (Incoming)

graph LR sendToActiveTab["sendToActiveTab"] handleMessage["handleMessage"] render["render"] handleMessage -->|uses| sendToActiveTab sendToActiveTab -->|uses| sendToActiveTab render -->|uses| sendToActiveTab style sendToActiveTab fill:#dbeafe,stroke:#2563eb,stroke-width:2px click sendToActiveTab "a91f63e9f38af9db.html" click handleMessage "58fadf6b36b326d5.html" click render "89e5905fc5b1676c.html"
SourceType
handleMessage uses
sendToActiveTab uses
render uses