Comlink keeps a map of promises waiting for replies and nothing ever empties it. If the worker crashes or the frame is closed, every call in flight waits forever. Here three things notice a departure. A page that is closing says goodbye on every link it holds. The port's new close event is used where the browser has it. And an optional heartbeat catches a side that crashed without a word. Whichever comes first, every pending call rejects with a LinkClosedError, and so does every later one. Ask the question, then remove the frame.
const api = wrap(port, { heartbeat: 1000, timeout: 30_000 });
try { await api.slow(); }
catch (error) { // LinkClosedError, or TimeoutError }
closed(api).then(() => showOffline());