Note: The badge for edge is an unofficial one made by Liozon. App icon from https://pixabay.com/vectors/suspension-bridge-golden-gate-bridge-161705/
A cross-browser extension to suspend inactive / unused tabs by "hiding" them behind a static, generic browser error page. Basically to suspend https://moshe-gr.com, it will be redirected to http://localhost:0/#https://www.moshe-gr.com (try it ;) ).
The great suspender was an extension that would automatically replace an open tab with a static, low memory page that would redirect back to the original on demand or after a set idle time. After a change of ownership, it was abused to contain malware, and therefore removed by Google.
Looking to avoid another extension by an unknown developer (who can always change), I opted to find a safer solution. I believe I have found it and want to share it in a way that can let others use / replicate it for their own benefit, at the level of knowledge and safety they require.
-
No static page - cannot be abused without changing the logic in a noticeable way.
-
Hash parameter - not sent to a server by the browser, by design.
-
I decided to use localhost:0 as a "host" to keep things local, and on a port that shouldn't conflict with other services / local servers.
-
Simple code base - easy to fork, install manually, and if necessary - replicate.
-
The core of the script boils down to:
const suspendPrefix = "https://localhost:0/#"; const toggleSuspendUrl = (pageUrl) => pageUrl.startsWith(suspendPrefix) ? pageUrl.replace(suspendPrefix, "") : `${suspendPrefix}${pageUrl}`; if (browser) { browser.browserAction.onClicked.addListener((tab) => { browser.tabs.update(tab.id, { url: toggleSuspendUrl(tab.url) }); }); }
-
-
The API I'm using doesn't require running Javascript code on the web page in the tab - just to get a page's URL. This makes the abuse potential minimal, and is reflected in the extensions limited permissions.
-
Advanced features, if/when added, will be "opt in" via a separate installation (on stores if / when I upload them) and branch (or possibly repository) - to always provide a stable, simple, and secure base version.
- Cannot unsuspend internal pages in Firefox, due to the following issue.
-
Clone the repo from Github.
-
Load the unpacked extension from the manifest-v3 folder (manifest-v2 will work too for now).
-
Clone the repo from Github.
-
Load the unpacked extension from the manifest-v3 folder (manifest-v2 will work too for now).
-
Clone the repo from Github.
-
Go to the Mozilla debugging page.
-
Press "Load Temporary Add-on..." and select the manifest-v2 folder (Mozilla doesn't support manifest-v3 at the time [July 2021]).
- Tabs API.
- Move tab to a new URL - tabs.update().
- discarded tabs - as documented here.
- Windows API.
- Get window URL - windows.getCurrent().
- Call via a page action.
- Schedule code to run at a specific time in the future using the alarm API.
- Idle recognition via the idle API.
Chrome error pages take over the window.location.href
attribute https://stackoverflow.com/questions/29989031/getting-the-current-domain-name-in-chrome-when-the-page-fails-to-load
I used a different selector when trying to run code from the page (not the current solution - recorded here in case it is needed):
document.querySelector(`[jscontent="failedUrl"]`)?.innerText;