import { MessageRequester , Message , JSONUint8Array , } from "@keplr-wallet/router" ; import { getKeplrExtensionRouterId } from "../utils" ; export class ContentScriptMessageRequester implements MessageRequester { async sendMessage < M extends Message < unknown > > ( port , msg ) { msg . validateBasic ( ) ; msg [ "origin" ] = window . location . origin ; msg . routerMeta = { ... msg . routerMeta , routerId : getKeplrExtensionRouterId ( ) , } ; const wrappedMsg = JSONUint8Array . wrap ( msg ) ; const tabs = await browser . tabs . query ( { discarded : false , status : "complete" , } ) ; for ( let i = 0 ; i < tabs . length ; i ++ ) { const tabId = tabs [ i ] . id ; if ( tabId ) { try { await browser . tabs . sendMessage ( tabId , { port , type : msg . type ( ) , msg : wrappedMsg , } ) ; } catch { } } } return undefined as any ; } }