Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to Manifest v3 #350

Closed
ssorallen opened this issue Sep 28, 2021 · 6 comments
Closed

Transition to Manifest v3 #350

ssorallen opened this issue Sep 28, 2021 · 6 comments

Comments

@ssorallen
Copy link
Member

Google Chrome is transitioning to Manifest V3, and Tab Wrangler needs to follow along. Tab Wrangler will be allowed to update on V2 through January 2023, but this transition would ideally happen well in advance of that to ensure operation continues uninterrupted.

@ssorallen ssorallen added enhancement chrome Issues specific to the Chrome browser labels Sep 28, 2021
@funblaster22
Copy link

funblaster22 commented Sep 12, 2022

Ok, I took a look at this issue and made my own fork with some changes, & it's really unfortunate that it seems MV3 doesn't have exactly suitable replacements for everything. Still need:

@ssorallen
Copy link
Member Author

Thanks for getting this started, @funblaster22. Google has a page about migrating from background pages to service workers: https://developer.chrome.com/docs/extensions/mv3/migrating_to_service_workers/

The following are things that need to happen:

  1. tabTimes needs to move into local storage. this will both fix some open issues (like Timer keeps reseting after restart and therefore tabs actually never close. #339) and ensure that when the service worker periodically starts up it will track tab times correctly
  2. set an alarm to wake up on the shortest period possible, which is 1 minute according to v3 docs, and keep the service worker running for roughly 1 minute. Service workers are forcibly shut down after 5 minutes (according to https://bugs.chromium.org/p/chromium/issues/detail?id=1152255) so Tab Wrangler's life cycle will look like the following:

0 -> service worker A (SWA) starts
5s -> SWA polls for tabs to close
10s -> SWA polls for tabs to close
...
60s -> SWA stops polling, removes alarm and event listeners (it will get cleaned up by the browser)
60s -> service worker B (SWB) starts
5s -> SWB polls for tabs to close
...
etc. etc. etc.

@ssorallen
Copy link
Member Author

ssorallen commented Sep 15, 2022

I believe the above setup will work correctly in the Chrome Manifest v3 world because no given service worker will live longer than 1 minute, and Tab Wrangler can still poll roughly every 5 seconds like it does now.

@ssorallen
Copy link
Member Author

ssorallen commented Jul 18, 2023

A contact on the Chrome Extensions dev relations team reached out and suggested using a heartbeat to keep the extensions existing background page alive after switching to Manifest v3.

Code example from the contact:

https://gist.github.com/patrickkettner/ab2e0f3a6341d41d9dbe81d42dfb04c4

async function runHeartbeat() {
  await chrome.storage.local.set({ "last-heartbeat": new Date().getTime() });
}

// Run the heartbeat once at service worker startup.
runHeartbeat().then(() => {
  // Then again every 20 seconds.
  setInterval(runHeartbeat, 20 * 1000);
});

/**
 * Returns the last heartbeat stored in extension storage, or undefined if
 * the heartbeat has never run before.
 */
async function getLastHeartbeat() {
  return (await chrome.storage.local.get("last-heartbeat"))["last-heartbeat"];
}

They also linked to a relevant discussion in the chromimum-extensions Google Group: https://groups.google.com/a/chromium.org/g/chromium-extensions/c/hWEe4I93P_E/m/BfLasiaPAQAJ?utm_medium=email&utm_source=footer

@ofek
Copy link

ofek commented Aug 1, 2023

What functionality will be lost after the upgrade?

@ssorallen
Copy link
Member Author

ssorallen commented Aug 2, 2023

@ofek As far as I know right now, no functionality will be lost. Thanks to the tip from the Chrome Extensions team, checking for stale tabs can work as it does right now. The most significant changes from Manifest v2 -> v3 are in functionality that Tab Wrangler does not use.

Tab Wrangler v7.0.0 will work on Manifest v3, and any user-facing changes will be documented in the release notes.

@ssorallen ssorallen removed the chrome Issues specific to the Chrome browser label Sep 19, 2023
ssorallen added a commit that referenced this issue Sep 20, 2023
Firefox's implementation of Manifest v3 supports
[background scripts][0], not service workers like Chrome's. Build
manifest.json separately for Chrome and for Firefox to support both
implementations.

* Wait 1s after activating to mark tab as fresh (new setting default)
* Split popup JS using async imports and React Suspense
* Require [dot-notation][1] via ESLint

Addresses #350

[0]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts
[1]: https://eslint.org/docs/latest/rules/dot-notation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants