// Asking the worker something, from anywhere in the popup. // // Its own module rather than a helper in popup.ts, because popup.ts imports // the cards and a card that needed this would import it back. import type { Msg } from '../lib/types' /** * A round trip to the background worker. The worker answers a thrown handler * with `{__error}` rather than by rejecting (a rejected sendResponse does not * survive the channel), so unwrap that back into a rejection here. */ export async function send(msg: Msg): Promise { const res = await chrome.runtime.sendMessage(msg) if (res && typeof res === 'object' && '__error' in res) { throw new Error(String((res as { __error: unknown }).__error)) } return res as T }