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
976 stars 171 forks source link

Update to manifest v3? #375

Open eric24601 opened 1 year ago

eric24601 commented 1 year ago

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

Thanks,

Eric

stale[bot] commented 11 months 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 9 months ago

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

Wizek commented 9 months 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 9 months 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 9 months ago

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