From c9710ac9d1adb65f56b115c5f43ab0ae298ef4c5 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 19 Jul 2021 11:25:52 -0400 Subject: [PATCH] Better deal with no-longer-existing ports Disconnected ports could still happen Even when the port was still seen as valid internally. Using a try-catch block makes invalid port detection more reliable. This is an occurrence I often encountered when stepping into content script code, causing suprious error messages to be thrown into uBO's background dev console. --- platform/common/vapi-background.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index 811a4095e..489f231fe 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -1086,11 +1086,13 @@ vAPI.messaging = { } proxy(response) { // https://github.com/chrisaljoudi/uBlock/issues/383 - if ( this.messaging.ports.has(this.port.name) ) { + try { this.port.postMessage({ msgId: this.msgId, msg: response !== undefined ? response : null, }); + } catch (ex) { + this.messaging.onPortDisconnect(this.port); } // Store for reuse this.port = null;