From b27f23d520bd5e7de4b564147e54b6e045a25cca Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Tue, 1 May 2018 13:28:21 +0200 Subject: [PATCH] Clear return value of vapi.js content script (#3721) Upon start-up, uBlock runs all content scripts in manifest.json using `chrome.tabs.executeScript`. When this API is used, the value of the last expression is automatically cloned and transferred to the callback of `chrome.tabs.executeScript`. This is convenient if needed, and a performance burden otherwise (the latter is the case for uBlock). There are three content scripts that need to be checked: - vapi.js The last expression is often the vAPI object, and it is relatively expensive to clone this object. This commit sets the value of the last expression to `void 0` to solve this inefficiency. - vapi-client.js No action needed yet; The last expression is `vAPI.shutdown.add(...)`, which has a void return value. - contentscript.js No action needed yet; The last expression is an immediately-invoked function expression without return value. --- platform/chromium/vapi.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/chromium/vapi.js b/platform/chromium/vapi.js index f62294041..a025e0402 100644 --- a/platform/chromium/vapi.js +++ b/platform/chromium/vapi.js @@ -53,4 +53,8 @@ if ( : { uBO: true }; } +// Set the value of the last expression to undefined to avoid serializing the +// vAPI object when the content script is run using chrome.tabs.executeScript. +void 0; + /******************************************************************************/