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

feat: improve adaptation of the extension for Chrome Web Store #1

Open
amerikan opened this issue Jul 17, 2023 · 2 comments
Open

feat: improve adaptation of the extension for Chrome Web Store #1

amerikan opened this issue Jul 17, 2023 · 2 comments
Assignees
Labels
status:blocked type:feature New feature or request

Comments

@amerikan
Copy link
Owner

amerikan commented Jul 17, 2023

As of now the extension is using Manifest v2 which is no longer supported by Chrome Web Store.

In Firefox, v3 support is currently limited when it comes to background scripts. v3 requires service_worker for background script, however, it's currently not enabled in Firefox's v3 manifest yet (officially tracked here). :(

@amerikan amerikan self-assigned this Jul 17, 2023
@amerikan amerikan changed the title feat: create Chrome extension counter part feat: create extension for Chrome Web Store Jul 17, 2023
@amerikan
Copy link
Owner Author

amerikan commented Aug 5, 2023

The following changes seem to work. Some changes needed are specifically for Manifest v3, but other are changes needed specifically for Chrome compatibility. For example Chrome uses chrome namespace instead of browser namespace ( see https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Build_a_cross_browser_extension#api_namespace and https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities#javascript_apis).

Though Firefox uses browser namespace, the chrome namespace also works so going forward it might be better to use that to make it cross-browser, not sure if there are any downsides to it.

diff --git a/src/background.js b/src/background.js
index 24e09e2..e15b47b 100644
--- a/src/background.js
+++ b/src/background.js
@@ -1,5 +1,5 @@
 async function removeDuplicateTabs() {
-  const tabs = await browser.tabs.query({});
+  const tabs = await chrome.tabs.query({});
 
   const duplicateIds = [];
   const bins = {};
@@ -12,11 +12,11 @@ async function removeDuplicateTabs() {
     }
   });
 
-  await browser.tabs.remove(duplicateIds);
+  await chrome.tabs.remove(duplicateIds);
 }
 
 async function groupTabsByDomain() {
-  const tabs = await browser.tabs.query({});
+  const tabs = await chrome.tabs.query({});
 
   const domainGroups = {};
 
@@ -39,7 +39,7 @@ async function groupTabsByDomain() {
     });
   }
 
-  await browser.tabs.move(newTabPositionIds, {
+  await chrome.tabs.move(newTabPositionIds, {
     index: 0,
   });
 }
@@ -54,4 +54,4 @@ async function handleToolbarButtonClick() {
   }
 }
 
-browser.browserAction.onClicked.addListener(handleToolbarButtonClick);
+chrome.action.onClicked.addListener(handleToolbarButtonClick);
diff --git a/src/manifest.json b/src/manifest.json
index 3423155..9138ba9 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -1,5 +1,5 @@
 {
-    "manifest_version": 2,
+    "manifest_version": 3,
     "name": "Tabtastic",
     "version": "1.0.2",
     "description": "Adds a browser button to help you sort tabs by domain and date, and close duplicate tabs.",
@@ -13,10 +13,10 @@
     "permissions": [
         "tabs"
     ],
-    "browser_action": {
+    "action": {
       "default_icon": "icons/icon.svg"
     },
     "background": {
-        "scripts": ["background.js"]
+        "service_worker": "background.js"
     }
   }

@amerikan amerikan added the type:feature New feature or request label Aug 7, 2023
@amerikan
Copy link
Owner Author

amerikan commented Oct 3, 2023

For chrome.* vs browser.* future consolidation see w3c/webextensions#113

@amerikan amerikan changed the title feat: create extension for Chrome Web Store feat: improve adaptation of the extension for Chrome Web Store Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:blocked type:feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant