diff options
Diffstat (limited to 'platform/common/vapi-client.js')
-rw-r--r-- | platform/common/vapi-client.js | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/platform/common/vapi-client.js b/platform/common/vapi-client.js index 9375e88..a6d46c6 100644 --- a/platform/common/vapi-client.js +++ b/platform/common/vapi-client.js @@ -22,10 +22,6 @@ // For non-background page -/* globals browser */ - -'use strict'; - /******************************************************************************/ // https://github.com/chrisaljoudi/uBlock/issues/456 @@ -85,6 +81,7 @@ vAPI.messaging = { portTimerDelay: 10000, msgIdGenerator: 1, pending: new Map(), + waitStartTime: 0, shuttingDown: false, shutdown: function() { @@ -115,16 +112,11 @@ vAPI.messaging = { // revisited to isolate the picker dialog DOM from the page DOM. messageListener: function(details) { if ( typeof details !== 'object' || details === null ) { return; } - - // Response to specific message previously sent - if ( details.msgId !== undefined ) { - const resolver = this.pending.get(details.msgId); - if ( resolver !== undefined ) { - this.pending.delete(details.msgId); - resolver(details.msg); - return; - } - } + if ( details.msgId === undefined ) { return; } + const resolver = this.pending.get(details.msgId); + if ( resolver === undefined ) { return; } + this.pending.delete(details.msgId); + resolver(details.msg); }, messageListenerBound: null, @@ -203,13 +195,18 @@ vAPI.messaging = { // the main process is no longer reachable: memory leaks and bad // performance become a risk -- especially for long-lived, dynamic // pages. Guard against this. - if ( this.pending.size > 50 ) { - vAPI.shutdown.exec(); + if ( this.pending.size > 64 ) { + if ( (Date.now() - this.waitStartTime) > 60000 ) { + vAPI.shutdown.exec(); + } } const port = this.getPort(); if ( port === null ) { return Promise.resolve(); } + if ( this.pending.size === 0 ) { + this.waitStartTime = Date.now(); + } const msgId = this.msgIdGenerator++; const promise = new Promise(resolve => { this.pending.set(msgId, resolve); |