瀏覽代碼

ignore error when sending "onLazyTimeout" message

Gildas 6 年之前
父節點
當前提交
6c2d6137d5
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      lib/lazy/bg/lazy-timeout.js

+ 7 - 1
lib/lazy/bg/lazy-timeout.js

@@ -29,7 +29,13 @@ singlefile.lib.lazy.bg.main = (() => {
 
 	browser.runtime.onMessage.addListener((message, sender) => {
 		if (message.method == "lazyTimeout.setTimeout") {
-			const timeoutId = setTimeout(() => browser.tabs.sendMessage(sender.tab.id, { method: "content.onLazyTimeout", id: timeoutId }), message.delay);
+			const timeoutId = setTimeout(async () => {
+				try {
+					await browser.tabs.sendMessage(sender.tab.id, { method: "content.onLazyTimeout", id: timeoutId });
+				} catch (error) {
+					// ignored
+				}
+			}, message.delay);
 			return Promise.resolve(timeoutId);
 		}
 		if (message.method == "lazyTimeout.clearTimeout") {