/** * The page channel across the two worlds of a browser extension. The runtime * lives in the page's MAIN world, which has no `chrome.runtime`; the content * script in the ISOLATED world has one but cannot share objects with the page. * The only thing both see is the window's message stream, so the runtime talks * over `window.postMessage` ({@link windowPageTransport}) and the content * script pipes that to a `chrome.runtime.Port` ({@link relayWindowToPort}), * whose other end is the DevTools panel's local host (see `port-link.ts`). * * Every message is an {@link Envelope} tagged with {@link SOURCE} and a * direction, because both worlds receive every message on the window, * including their own, and so does the page's own code. Each end drops its * own direction and anything that is not an envelope, and only listens to * messages whose `event.source` is the window they listen on. * * Trust: the page can read and forge all of this. That is acceptable, since * the page is the data source anyway. What matters is that a forged envelope * can do nothing a page could not already do through the port: the relay only * forwards `{channel, data}` to the port, which the panel treats as page * traffic, and it never interprets `data`. Conversely everything the panel * sends is readable by the page, so the panel must not send anything secret. * * Window messages are structured-cloned and port messages JSON-serialized; * every `lit:*` payload is already JSON-safe (the Vite HMR channel needs it), * so there is no extra serialization step. * * Late connects: the panel may open after the page booted, or close and open * again. The relay announces itself with a `connected` control message when it * starts, and answers the page's `hello` the same way, so the page re-attaches * and the runtime re-announces itself ({@link attachWindowTransport}). Page * sends made before any relay exists are dropped, which that re-announce * covers. A relay whose port outlives a panel (the extension opens it per * document, not per panel) says `connected` again whenever the port brings * {@link PEER_CONNECTED_CHANNEL}. */ import type { PageTransport } from './page-channel.js'; import type { PortLike } from '../devframe/port-message.js'; /** Marks window messages as ours among all other `postMessage` traffic. */ export declare const SOURCE = "@oddsquad/vite-plugin-lit"; export interface WindowPageTransportOptions { /** The window to talk through. Defaults to `window`. */ target?: Window; /** Called each time a relay announces itself, first or again. */ onPeerConnected?: () => void; } /** MAIN world: a PageTransport over window.postMessage to the extension's content script. */ export declare const windowPageTransport: (options?: WindowPageTransportOptions) => PageTransport; /** * MAIN world entry: make the window the runtime's carrier, and re-attach it * whenever a relay (re)connects so the runtime announces itself to the new * peer. Re-attaching the same transport is safe: `pageChannel.attach` unbinds * its listeners before binding them again. */ export declare const attachWindowTransport: (target?: Window) => PageTransport; /** ISOLATED world: pipe the page's window messages to `port` and back. Returns a stop function. */ export declare const relayWindowToPort: (target: Window, port: PortLike) => (() => void); //# sourceMappingURL=window-transport.d.ts.map