Skip to content

Commit

Permalink
Prevent uBO from being reloaded mid-session
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-issues#717

Just registering a onUpdateAvailable() listener prevents
the browser from reloading the extension mid-session.

Ref:
- https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onUpdateAvailable
  • Loading branch information
gorhill committed Sep 4, 2019
1 parent b5e34f1 commit 59bdf2b
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

/******************************************************************************/

(( ) => {
{
// >>>>> start of local scope

/******************************************************************************/
/******************************************************************************/
Expand Down Expand Up @@ -65,32 +66,35 @@ const noopFunc = function(){};

/******************************************************************************/

vAPI.app = (function() {
let version = manifest.version;
let match = /(\d+\.\d+\.\d+)(?:\.(\d+))?/.exec(version);
if ( match && match[2] ) {
let v = parseInt(match[2], 10);
version = match[1] + (v < 100 ? 'b' + v : 'rc' + (v - 100));
}

return {
name: manifest.name.replace(/ dev\w+ build/, ''),
version: version
};
})();

/******************************************************************************/
vAPI.app = {
name: manifest.name.replace(/ dev\w+ build/, ''),
version: (( ) => {
let version = manifest.version;
const match = /(\d+\.\d+\.\d+)(?:\.(\d+))?/.exec(version);
if ( match && match[2] ) {
const v = parseInt(match[2], 10);
version = match[1] + (v < 100 ? 'b' + v : 'rc' + (v - 100));
}
return version;
})(),

vAPI.app.restart = function() {
chrome.runtime.reload();
restart: function() {
browser.runtime.reload();
},
};

// https://github.com/uBlockOrigin/uBlock-issues/issues/717
// Prevent the extensions from being restarted mid-session.
browser.runtime.onUpdateAvailable.addListener(( ) => {
void 0;
});

/******************************************************************************/
/******************************************************************************/

// chrome.storage.local.get(null, function(bin){ console.debug('%o', bin); });

vAPI.storage = chrome.storage.local;
vAPI.storage = browser.storage.local;

/******************************************************************************/
/******************************************************************************/
Expand Down Expand Up @@ -217,7 +221,7 @@ vAPI.browserSettings = (function() {
},

set: function(details) {
for ( var setting in details ) {
for ( const setting in details ) {
if ( details.hasOwnProperty(setting) === false ) {
continue;
}
Expand Down Expand Up @@ -1222,11 +1226,10 @@ vAPI.contextMenu = chrome.contextMenus && {
onMustUpdate: function() {},
setEntries: function(entries, callback) {
entries = entries || [];
var n = Math.max(this._entries.length, entries.length),
oldEntryId, newEntry;
for ( var i = 0; i < n; i++ ) {
oldEntryId = this._entries[i];
newEntry = entries[i];
let n = Math.max(this._entries.length, entries.length);
for ( let i = 0; i < n; i++ ) {
const oldEntryId = this._entries[i];
const newEntry = entries[i];
if ( oldEntryId && newEntry ) {
if ( newEntry.id !== oldEntryId ) {
chrome.contextMenus.remove(oldEntryId);
Expand Down Expand Up @@ -1277,8 +1280,8 @@ vAPI.commands = chrome.commands;

vAPI.adminStorage = chrome.storage.managed && {
getItem: function(key, callback) {
var onRead = function(store) {
var data;
const onRead = function(store) {
let data;
if (
!chrome.runtime.lastError &&
typeof store === 'object' &&
Expand Down Expand Up @@ -1513,6 +1516,7 @@ vAPI.cloud = (function() {
/******************************************************************************/
/******************************************************************************/

})();
// <<<<< end of local scope
}

/******************************************************************************/

0 comments on commit 59bdf2b

Please sign in to comment.