Преглед на файлове

prevent infinite "idleTimeout" messages (fix #780)

Gildas преди 4 години
родител
ревизия
61358a3460
променени са 1 файла, в които са добавени 6 реда и са изтрити 1 реда
  1. 6 1
      lib/single-file/processors/lazy/content/content-lazy-loader.js

+ 6 - 1
lib/single-file/processors/lazy/content/content-lazy-loader.js

@@ -33,6 +33,7 @@ const helper = {
 	SINGLE_FILE_UI_ELEMENT_CLASS
 };
 
+const MAX_IDLE_TIMEOUT_CALLS = 10;
 const ATTRIBUTES_MUTATION_TYPE = "attributes";
 
 const browser = globalThis.browser;
@@ -42,6 +43,8 @@ const addEventListener = (type, listener, options) => globalThis.addEventListene
 const removeEventListener = (type, listener, options) => globalThis.removeEventListener(type, listener, options);
 const timeouts = new Map();
 
+let idleTimeoutCalls;
+
 if (browser && browser.runtime && browser.runtime.onMessage && browser.runtime.onMessage.addListener) {
 	browser.runtime.onMessage.addListener(message => {
 		if (message.method == "singlefile.lazyTimeout.onTimeout") {
@@ -79,6 +82,7 @@ function resetZoomLevel(options) {
 }
 
 function triggerLazyLoading(options) {
+	idleTimeoutCalls = 0;
 	return new Promise(async resolve => { // eslint-disable-line  no-async-promise-executor
 		let loadingImages;
 		const pendingImages = new Set();
@@ -116,7 +120,8 @@ function triggerLazyLoading(options) {
 					clearAsyncTimeout("loadTimeout");
 					clearAsyncTimeout("maxTimeout");
 					lazyLoadEnd(observer, options, cleanupAndResolve);
-				} else {
+				} else if (idleTimeoutCalls < MAX_IDLE_TIMEOUT_CALLS) {
+					idleTimeoutCalls++;
 					clearAsyncTimeout("idleTimeout");
 					await setIdleTimeout(Math.max(500, delay / 2));
 				}