Do not rely on `vAPI` presence in logger broadcast code

Related feedback:
https://github.com/uBlockOrigin/uBlock-issues/discussions/3096#discussioncomment-8339494
This commit is contained in:
Raymond Hill 2024-02-02 09:15:09 -05:00
parent 605c830312
commit b0122bb9fc
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 6 additions and 12 deletions

View File

@ -175,9 +175,7 @@ const onScriptletMessageInjector = (( ) => {
const parts = [
'(',
function(name) {
if ( typeof vAPI !== 'object' ) { return; }
if ( vAPI === null ) { return; }
if ( vAPI.bcSecret ) { return; }
if ( self.uBO_bcSecret ) { return; }
const bcSecret = new self.BroadcastChannel(name);
bcSecret.onmessage = ev => {
const msg = ev.data;
@ -189,14 +187,12 @@ const onScriptletMessageInjector = (( ) => {
case 'object':
if ( self.vAPI && self.vAPI.messaging ) {
self.vAPI.messaging.send('contentscript', msg);
} else {
bcSecret.onmessage = null;
}
break;
}
};
bcSecret.postMessage('iamready!');
vAPI.bcSecret = bcSecret;
self.uBO_bcSecret = bcSecret;
}.toString(),
')(',
'bcSecret-slot',

View File

@ -24,9 +24,8 @@
/******************************************************************************/
(( ) => {
if ( typeof vAPI !== 'object' || vAPI === null ) { return; }
if ( vAPI.bcSecret instanceof self.BroadcastChannel === false ) { return; }
vAPI.bcSecret.postMessage('setScriptletLogLevelToOne');
if ( self.uBO_bcSecret instanceof self.BroadcastChannel === false ) { return; }
self.uBO_bcSecret.postMessage('setScriptletLogLevelToOne');
})();

View File

@ -24,9 +24,8 @@
/******************************************************************************/
(( ) => {
if ( typeof vAPI !== 'object' || vAPI === null ) { return; }
if ( vAPI.bcSecret instanceof self.BroadcastChannel === false ) { return; }
vAPI.bcSecret.postMessage('setScriptletLogLevelToTwo');
if ( self.uBO_bcSecret instanceof self.BroadcastChannel === false ) { return; }
self.uBO_bcSecret.postMessage('setScriptletLogLevelToTwo');
})();