From eed13194fb10ccd3d64a5cf92cf2252dffc46730 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 21 May 2019 14:07:38 -0400 Subject: [PATCH] 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. --- platform/chromium/vapi-background.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index f68fcee7f..526d5c618 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -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); + } } };