Fix potential failure to unregister scriptlet

In Firefox-specific contentScripts API used to register
scriptlets. This could potentially occurs when there are
registrations pending during a reload of filter lists.
This commit is contained in:
Raymond Hill 2024-09-14 09:31:22 -04:00
parent 41d49921c8
commit f936dfa648
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -61,6 +61,7 @@ const contentScriptRegisterer = new (class {
runAt: 'document_start', runAt: 'document_start',
}).then(handle => { }).then(handle => {
this.hostnameToDetails.set(hostname, { handle, code }); this.hostnameToDetails.set(hostname, { handle, code });
return handle;
}).catch(( ) => { }).catch(( ) => {
this.hostnameToDetails.delete(hostname); this.hostnameToDetails.delete(hostname);
}); });
@ -94,7 +95,9 @@ const contentScriptRegisterer = new (class {
} }
unregisterHandle(handle) { unregisterHandle(handle) {
if ( handle instanceof Promise ) { if ( handle instanceof Promise ) {
handle.then(handle => { handle.unregister(); }); handle.then(handle => {
if ( handle ) { handle.unregister(); }
});
} else { } else {
handle.unregister(); handle.unregister();
} }