import { RpcClient, RpcServer } from 'webextension-rpc'; import type { RpcInfo } from 'webextension-rpc'; // Only import the *types* of the remote script’s functions. import type { contentScriptRpcServer } from './content-script'; // From background to content script. const contentScriptRpc = new RpcClient({ tabId: 123 }); const setColour = contentScriptRpc.func('setColour'); await setColour('blue'); // From content to background script. const backgroundScriptRpcServer = new RpcServer({ async duplicateTab(rpcInfo: RpcInfo, active: boolean) { const newTab = await browser.tabs.duplicate(rpcInfo.tab.id, { active }); return newTab.id; }, async timesTwo(x: number) { return 2 * x }, }); export type { backgroundScriptRpcServer }