Skip to content

Commit

Permalink
[CRX] Remove restoretab.js logic
Browse files Browse the repository at this point in the history
restoretab.js was added in mozilla#6233
with the purpose of restoring lost tabs when Chrome closes all extension
tabs when it reloads the extension. This forced reload can happen when
the user toggles the "Allow access to file URLs" option.

This logic does not work any more, and since the use of localStorage is
a blocker in migrating to MV3, this patch just drops the logic.
  • Loading branch information
Rob--W committed Sep 1, 2024
1 parent 5410277 commit 3239072
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 90 deletions.
24 changes: 0 additions & 24 deletions extensions/chromium/extension-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,4 @@ limitations under the License.
}
);
console.log("Set up extension URL router.");

Object.keys(localStorage).forEach(function (key) {
// The localStorage item is set upon unload by chromecom.js.
var parsedKey = /^unload-(\d+)-(true|false)-(.+)/.exec(key);
if (parsedKey) {
var timeStart = parseInt(parsedKey[1], 10);
var isHidden = parsedKey[2] === "true";
var url = parsedKey[3];
if (Date.now() - timeStart < 3000) {
// Is it a new item (younger than 3 seconds)? Assume that the extension
// just reloaded, so restore the tab (work-around for crbug.com/511670).
chrome.tabs.create({
url:
chrome.runtime.getURL("restoretab.html") +
"?" +
encodeURIComponent(url) +
"#" +
encodeURIComponent(localStorage.getItem(key)),
active: !isHidden,
});
}
localStorage.removeItem(key);
}
});
})();
17 changes: 0 additions & 17 deletions extensions/chromium/restoretab.html

This file was deleted.

31 changes: 0 additions & 31 deletions extensions/chromium/restoretab.js

This file was deleted.

18 changes: 0 additions & 18 deletions web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,24 +249,6 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) {
});
}

if (window === top) {
// Chrome closes all extension tabs (crbug.com/511670) when the extension
// reloads. To counter this, the tab URL and history state is saved to
// localStorage and restored by extension-router.js.
// Unfortunately, the window and tab index are not restored. And if it was
// the only tab in an incognito window, then the tab is not restored either.
addEventListener("unload", function () {
// If the runtime is still available, the unload is most likely a normal
// tab closure. Otherwise it is most likely an extension reload.
if (!isRuntimeAvailable()) {
localStorage.setItem(
"unload-" + Date.now() + "-" + document.hidden + "-" + location.href,
JSON.stringify(history.state)
);
}
});
}

let dnrRequestId;
// This port is used for several purposes:
// 1. When disconnected, the background page knows that the frame has unload.
Expand Down

0 comments on commit 3239072

Please sign in to comment.