Prevent contentScripts.register from throwing

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/2915
This commit is contained in:
Raymond Hill 2023-10-30 10:44:04 -04:00
parent bc632b5464
commit b061db229e
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -78,6 +78,7 @@ const contentScriptRegisterer = new (class {
}
register(hostname, code) {
if ( browser.contentScripts === undefined ) { return false; }
if ( hostname === '' ) { return false; }
const details = this.hostnameToDetails.get(hostname);
if ( details !== undefined ) {
if ( code === details.code ) {
@ -94,6 +95,8 @@ const contentScriptRegisterer = new (class {
runAt: 'document_start',
}).then(handle => {
this.hostnameToDetails.set(hostname, { handle, code });
}).catch(( ) => {
this.hostnameToDetails.delete(hostname);
});
this.hostnameToDetails.set(hostname, { handle: promise, code });
return false;