11import '@/js/browser' ;
22import { kTabOvr , pExposeIframes , pStyleViaASS } from '@/js/consts' ;
33import { rxIgnorableError } from '@/js/msg-api' ;
4- import { ownRoot } from '@/js/urls' ;
54import { sleep0 } from '@/js/util' ;
65import { isOptionSite , optionSites } from './option-sites' ;
76import { tabCache } from './tab-manager' ;
@@ -11,6 +10,7 @@ let toBroadcast;
1110let toBroadcastCfg ;
1211let toBroadcastUpdStyles ;
1312const OLD = Symbol ( 'old' ) ;
13+ const channel = new BroadcastChannel ( 'sw' ) ;
1414
1515export function broadcast ( data , cfg ) {
1616 toBroadcast ??= ( setTimeout ( doBroadcast ) , [ ] ) ;
@@ -49,22 +49,24 @@ async function doBroadcast() {
4949 const tabOverrides = tabCache [ t . id ] ?. [ kTabOvr ] ;
5050 const patched = tabOverrides && Object . keys ( tabOverrides ) . length &&
5151 patchStyles ( updStyles , tabOverrides ) ;
52- if ( ! url . startsWith ( ownRoot ) || patched ) {
53- if ( assSites ) cfg . ass = isOptionSite ( assSites , url ) ;
54- if ( iframeSites ) cfg . top = isOptionSite ( iframeSites , url ) ;
55- sendTab ( t . id , data , null , true ) ;
56- if ( patched ) for ( const p of patched ) p . enabled = p [ OLD ] ;
57- /* Broadcast messages are tiny, but sending them takes some time anyway,
58- so we're yielding for a possible navigation/messaging event. */
59- if ( ++ cnt > 50 ) {
60- cnt = 0 ;
61- await sleep0 ( ) ;
62- }
52+ if ( assSites ) cfg . ass = isOptionSite ( assSites , url ) ;
53+ if ( iframeSites ) cfg . top = isOptionSite ( iframeSites , url ) ;
54+ sendTab ( t . id , data , null , true ) ;
55+ if ( patched ) for ( const p of patched ) p . enabled = p [ OLD ] ;
56+ /* Broadcast messages are tiny, but sending them takes some time anyway,
57+ so we're yielding for a possible navigation/messaging event. */
58+ if ( ++ cnt > 50 ) {
59+ cnt = 0 ;
60+ await sleep0 ( ) ;
6361 }
6462 }
6563}
6664
6765export function broadcastExtension ( data , multi ) {
66+ if ( __ . MV3 ) {
67+ channel . postMessage ( { id : 1 , args : [ data , { } , multi , /*broadcast*/ true ] } ) ;
68+ return ;
69+ }
6870 return unwrap ( browser . runtime . sendMessage ( { data, multi, broadcast : true } ) ) ;
6971}
7072
0 commit comments