Parcourir la source

ignore errors when calling dispatchEvent (fix #958)

Gildas il y a 3 ans
Parent
commit
0665e61b19

+ 2 - 1
cli/back-ends/extensions/network-idle/content.js

@@ -24,5 +24,6 @@
 /* global window, CustomEvent */
 
 const browserAPI = this.browser || this.chrome;
+const dispatchEvent = event => { try { window.dispatchEvent(event); } catch (error) {  /* ignored */ } };
 
-browserAPI.runtime.onMessage.addListener(message => window.dispatchEvent(new CustomEvent("single-file-" + message)));
+browserAPI.runtime.onMessage.addListener(message => dispatchEvent(new CustomEvent("single-file-" + message)));

+ 1 - 1
src/single-file/processors/hooks/content/content-hooks-frames-web.js

@@ -54,7 +54,7 @@
 	};
 
 	const addEventListener = (type, listener, options) => globalThis.addEventListener(type, listener, options);
-	const dispatchEvent = event => globalThis.dispatchEvent(event);
+	const dispatchEvent = event => { try { globalThis.dispatchEvent(event); } catch (error) {  /* ignored */ } };
 	const CustomEvent = globalThis.CustomEvent;
 	const document = globalThis.document;
 	const screen = globalThis.screen;

+ 1 - 1
src/single-file/processors/hooks/content/content-hooks-frames.js

@@ -43,7 +43,7 @@ const CLEAR_FONTS_EVENT = "single-file-clear-fonts";
 
 const browser = globalThis.browser;
 const addEventListener = (type, listener, options) => globalThis.addEventListener(type, listener, options);
-const dispatchEvent = event => globalThis.dispatchEvent(event);
+const dispatchEvent = event => { try { globalThis.dispatchEvent(event); } catch (error) {  /* ignored */ } };
 const CustomEvent = globalThis.CustomEvent;
 const document = globalThis.document;
 const Document = globalThis.Document;

+ 1 - 1
src/single-file/processors/hooks/content/content-hooks-web.js

@@ -31,7 +31,7 @@
 	const CustomEvent = globalThis.CustomEvent;
 	const fetch = globalThis.fetch;
 	const addEventListener = (type, listener, options) => globalThis.addEventListener(type, listener, options);
-	const dispatchEvent = event => globalThis.dispatchEvent(event);
+	const dispatchEvent = event => { try { globalThis.dispatchEvent(event); } catch (error) {  /* ignored */ } };
 
 	addEventListener(FETCH_REQUEST_EVENT, async event => {
 		const url = event.detail;

+ 1 - 1
src/single-file/single-file-helper.js

@@ -63,7 +63,7 @@ const COMMENT_HEADER_LEGACY = "Archive processed by SingleFile";
 const SINGLE_FILE_UI_ELEMENT_CLASS = "single-file-ui-element";
 const EMPTY_RESOURCE = "data:,";
 const addEventListener = (type, listener, options) => globalThis.addEventListener(type, listener, options);
-const dispatchEvent = event => globalThis.dispatchEvent(event);
+const dispatchEvent = event => { try { globalThis.dispatchEvent(event); } catch (error) {  /* ignored */ } };
 
 export {
 	initUserScriptHandler,