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

Handle possible exceptions in vAPI.messaging.broadcast()

I had exceptions thrown by that code once in a while,
about the `port` object not being connected; possibly
occurs only when using dev tools with breakpoints
in uBO's code. Even if this can be reproduced randomly
only when debugging uBO, it costs nothing to add code
in there to handle exceptions.
This commit is contained in:
Raymond Hill 2019-05-21 14:07:38 -04:00
parent 32b04fa262
commit eed13194fb
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1021,12 +1021,13 @@ vAPI.messaging.setup = function(defaultHandler) {
/******************************************************************************/
vAPI.messaging.broadcast = function(message) {
var messageWrapper = {
broadcast: true,
msg: message
};
for ( var port of this.ports.values() ) {
port.postMessage(messageWrapper);
const messageWrapper = { broadcast: true, msg: message };
for ( const port of this.ports.values() ) {
try {
port.postMessage(messageWrapper);
} catch(ex) {
this.ports.delete(port.name);
}
}
};