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.
This commit is contained in:
Raymond Hill 2021-07-19 11:25:52 -04:00
parent efca367694
commit c9710ac9d1
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -1086,11 +1086,13 @@ vAPI.messaging = {
} }
proxy(response) { proxy(response) {
// https://github.com/chrisaljoudi/uBlock/issues/383 // https://github.com/chrisaljoudi/uBlock/issues/383
if ( this.messaging.ports.has(this.port.name) ) { try {
this.port.postMessage({ this.port.postMessage({
msgId: this.msgId, msgId: this.msgId,
msg: response !== undefined ? response : null, msg: response !== undefined ? response : null,
}); });
} catch (ex) {
this.messaging.onPortDisconnect(this.port);
} }
// Store for reuse // Store for reuse
this.port = null; this.port = null;