summaryrefslogtreecommitdiffstats
path: root/platform/common/vapi-client.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 05:50:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 05:50:18 +0000
commit55a5d29a66503248916f249ad2a1d8b37cde5a03 (patch)
treea3beb6a90dd3bdaaf67ecb05d42152a494aff946 /platform/common/vapi-client.js
parentAdding upstream version 1.55.0+dfsg. (diff)
downloadublock-origin-55a5d29a66503248916f249ad2a1d8b37cde5a03.tar.xz
ublock-origin-55a5d29a66503248916f249ad2a1d8b37cde5a03.zip
Adding upstream version 1.57.0+dfsg.upstream/1.57.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'platform/common/vapi-client.js')
-rw-r--r--platform/common/vapi-client.js29
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);