1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

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) {
// 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;