import { browser } from "webextension-polyfill-ts" ; import { Message , MessageResponse } from "../types/types" ; export const sendMessageToActiveTab = ( message ) : Promise < MessageResponse > => browser . tabs . query ( { active : true , lastFocusedWindow : true } ) . then ( tabs => { if ( tabs . length !== 0 && tabs [ 0 ] . id ) { return browser . tabs . sendMessage ( tabs [ 0 ] . id , message ) ; } else { return new Promise ( resolve => resolve ( "failure" ) ) ; } } ) ;