import { remoteFunction, makeRemotelyCallable } from 'webextension-rpc'; import type { RpcInfo } from 'webextension-rpc'; // Only import the *types* of the remote script’s functions. import type { contentScriptRemoteFunctions } from './content-script'; // From background to content script. const setColour = remoteFunction( 'setColour', { tabId: 123 }, ); await setColour('blue'); // From content to background script. export const backgroundScriptRemoteFunctions = makeRemotelyCallable({ async duplicateTab(rpcInfo: RpcInfo, active: boolean) { const newTab = await browser.tabs.duplicate(rpcInfo.tab.id, { active }); return newTab.id; }, });