handleMessage function application
Last updated: 2026-03-02T11:04:50.991Z
Metrics
LOC: 25
Complexity: 6
Params: 1
Signature
handleMessage(message: ExtensionMessage): : Promise<unknown>
Source Code
async function handleMessage(message: ExtensionMessage): Promise<unknown> {
// DevTools relay: forward inner message to a specific tab's content script
if (message.type === "DEVTOOLS_RELAY") {
const payload = message.payload as
| { tabId: number; message: ExtensionMessage }
| undefined;
if (!payload?.tabId || !payload?.message) {
return { error: "Invalid DEVTOOLS_RELAY payload" };
}
return sendToSpecificTab(payload.tabId, undefined, payload.message, {
injectIfNeeded: true,
});
}
// Forward content-script-bound messages to the active tab
if (CONTENT_SCRIPT_MESSAGES.has(message.type)) {
return sendToActiveTab(message, { injectIfNeeded: true });
}
// Dispatch to the appropriate domain handler
const result = await dispatchMessage(message);
if (result !== null) return result;
return { error: `Unknown message type: ${message.type}` };
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| ExtensionMessage | uses |
| parseIncomingMessage | uses |
| sendToActiveTab | uses |
| sendToSpecificTab | uses |
| handleContextMenuClick | uses |
| initLogger | uses |
| createLogger | uses |
| destroySession | uses |
| destroyOptimizerSession | uses |
| disposeTensorflowModel | uses |
| setupContextMenu | calls |
| handleMessage | calls |
| dispatchMessage | calls |
| destroyClassifierSession | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| handleMessage | calls |