babyman / quick-tabs-chrome-extension

A quick tab list and switch plugin inspired by the intelliJ IDEA java IDE
BSD 3-Clause "New" or "Revised" License
984 stars 172 forks source link

Update to manifest v3? #375

Closed eric24601 closed 2 weeks ago

eric24601 commented 1 year ago

Hi, any plans to migrate the extension to manifest v3?

Thanks,

Eric

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Wizek commented 1 year ago

I'm also interested in this. Anyone knows if it's a simple port or if more involved?

Wizek commented 1 year ago

Some notes that might help us:

Converting a Chrome extension from Manifest V2 to Manifest V3 involves several key changes and considerations. The JSON snippet you've provided gives a good overview of the extension's current structure under Manifest V2. Let's go through the main points of conversion to Manifest V3:

  1. Background Scripts: In Manifest V3, traditional background pages are replaced by service workers. If background.js contains long-running scripts or relies on DOM APIs, it will need significant modifications. Service workers in V3 are designed to be ephemeral, waking up when needed (e.g., to handle events) and shutting down when idle.

  2. Browser Action: The browser_action field is replaced by action in Manifest V3. This is a straightforward change, primarily involving renaming the key in the manifest.

  3. Permissions: The permissions model remains largely the same in Manifest V3, but you should review them to ensure they align with the new privacy and security standards of V3.

  4. Host Permissions: If your extension uses host permissions (not visible in the provided snippet), they need to be migrated to the new host_permissions field.

  5. Content Security Policy (CSP): Manifest V3 enforces a more stringent CSP. This might require changes if your extension loads external resources.

  6. Manifest Version: Update manifest_version to 3.

  7. Storage: If your extension uses persistent background pages to store state, you may need to migrate to using the storage API, as service workers are terminated when idle.

  8. Event Pages: If the extension uses event pages, they need to be migrated to use service workers.

  9. Commands: The commands section seems straightforward and likely requires minimal changes, but you should verify compatibility with V3.

Overall, the difficulty of converting to Manifest V3 largely depends on how background.js and other scripts are structured. If they heavily rely on long-running scripts or synchronous XHR, the conversion can be complex. However, if the extension primarily reacts to events and doesn't rely on a persistent background page, the conversion should be relatively straightforward.

Remember to thoroughly test the extension after conversion, as some changes might affect its behavior in subtle ways.

Wizek commented 1 year ago

Some more notes on how involved changes to background.js might need to be:

After reviewing the background.js script from your Chrome extension, here are some key points regarding its conversion to Manifest V3:

  1. Service Workers vs. Persistent Background Scripts: The current script seems to be designed as a persistent background script. With Manifest V3, this needs to be converted to a service worker, which is ephemeral and gets terminated when not in use. This means that you will need to refactor long-running or stateful processes. For example, the use of setTimeout and setInterval should be reviewed, as service workers can be terminated by the browser at any time.

  2. Event Listeners: The script uses various Chrome event listeners (chrome.tabs.onUpdated, chrome.tabs.onActivated, etc.), which are compatible with Manifest V3. However, you should ensure that these listeners are registered each time the service worker starts up, as the worker may be stopped and started frequently.

  3. Global State: The script maintains global state (like tabs, closedTabs, etc.). In Manifest V3, due to the ephemeral nature of service workers, you might need to persist this state externally (e.g., using the chrome.storage API) and restore it when the service worker starts.

  4. Local Storage Access: The script uses localStorage for storing settings and state. In Manifest V3, you should migrate this to the chrome.storage API, which is more suitable for extensions and works asynchronously.

  5. Background Page Functionality: If any functionality in your background script relies on a persistent background page (e.g., maintaining a DOM or executing long-running tasks), it will need to be adapted for the service worker model, which does not support a persistent background page.

  6. Message Passing: The script uses chrome.runtime.onConnect for message passing. This is still valid in Manifest V3, but ensure that the communication pattern aligns with the ephemeral nature of service workers.

  7. Timers and Delays: Your script uses functions like setTimeout for delayed execution. In Manifest V3's service worker environment, these will need careful handling to ensure they're not dependent on the worker staying alive.

  8. Permissions and Manifest Changes: Besides updating the script, remember to update the manifest file to reflect Manifest V3 requirements, including updating the manifest_version to 3 and making any necessary changes to the permissions and other fields.

In summary, converting this extension to Manifest V3 will require significant refactoring, particularly around the state management and the transition from a persistent background script to an ephemeral service worker. The complexity of this conversion will depend on how deeply the current functionality is tied to the persistent background model and how much state needs to be managed across potential service worker restarts.

Maybe it can be done easier than what's suggested here?

babyman commented 1 year ago

Thanks for these notes, I'm trying to find some time to migrate Quick Tabs but life is crazy :)

tberry2112 commented 1 month ago

@babyman any plans to migrate Quick Tabs or should we all start looking for a replacement?

babyman commented 1 month ago

I really wish I had the time but I'm kidding myself :|.

The effort to migrate to the v3 manifest is just more work than I have time to undertake and I imagine Google will stop supporting v2 soon which is a shame.

hababr commented 1 month ago

@babyman That should not be hard. I could do this migration if you accept a pull request and make a release. Cause seems you do not have time even for this.

babyman commented 1 month ago

@hababr I'm very supportive of that and can make time to review and merge a migration. That would be fantastic!

hababr commented 1 month ago

If anyone is willing to test the migrated version that would be nice. https://github.com/hababr/quick-tabs-chrome-extension/tree/master

I need to do a couple of things before I make a pull request, but everything should work already.

tberry2112 commented 1 month ago

I just tried load unpacked and see a few errors:

image

image

hababr commented 1 month ago

@tberry2112 Thank you for the report! These issues happened on fresh install only, now they are fixed.

sabbott1877 commented 1 month ago

I'm running the latest V3 version and it seems to be working well. Thank you for taking this on! I did have to disable the old extension, then re-update the popup keyboard shortcut in chrome in order to get it to open on shortcut.

hababr commented 3 weeks ago

Hi @babyman, I opened a PR. Please ask anything if you are not sure about my changes.

babyman commented 3 weeks ago

Amazing, I'll take a look and let you know!

Thanks for this effort.

babyman commented 2 weeks ago

I have submitted the update to the Chrome Store for review, if it passes it will be published automatically. Thank you all for your efforts, very much appreciated!

I'll close this ticket once it's published.

babyman commented 2 weeks ago

And published, even with a Featured badge!

eric24601 commented 1 week ago

Woot! and congrats

rb-109 commented 3 days ago

@hababr I just wanted to say a huge THANK YOU for saving this must-have extension from extinction (and as always, thank you @babyman for creating it in the first place) I would like to buy you a coffee, if there was some way to make a donation to say thank you.

eric24601 commented 3 days ago

I would like to buy you a coffee, if there was some way to make a donation to say thank you.

Hi @hababr, I think this is the link for donations: https://ko-fi.com/quicktabs :-)

hababr commented 3 days ago

@rb-109 Agree with you this is a great extension. Babyman has a donation link in this repo.

rb-109 commented 3 days ago

@rb-109 Agree with you this is a great extension. Babyman has a donation link in this repo.

@hababr Thank you. In fact, I had found that link and have already donated to babyman, but in this case, I was asking whether YOU also had a donation page, because I wanted to thank you as well for writing the code to make the migration to manifest v3

babyman commented 3 days ago

@rb-109 thank you but that was unnecessary! I agree with you, this release really belongs to @hababr!