Something went wrong. Try again.
Browser extension: detect and subscribe to standard.site publications on ATProto
Something went wrong. Try again.
735 B · 19 lines
TypeScript
1234567891011121314151617181920// 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<T>(msg: Msg): Promise<T> { 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}