find icon indicating copy to clipboard operation
find copied to clipboard

Update manifest.json to v3

Open gers1978 opened this issue 2 years ago • 1 comments

Updated manifest from v2 to v3 compliance.

gers1978 avatar Apr 25 '23 21:04 gers1978

Thanks for the contribution! I'll have a look tonight or tomorrow :)

brandon1024 avatar Apr 26 '23 13:04 brandon1024

Hey @brandon1024 , there is a warning banner on Chrome web store:

This extension may soon no longer be supported because it doesn't follow best practices for Chrome extensions.

We may have to migrate to MV3 ASAP.

pzhlkj6612 avatar Dec 24 '24 13:12 pzhlkj6612

Any update on this? find+ is now not supported anymore and even if you had it installed previously, there's no functionality left. The only workaround is to use it on Firefox as MV2 is still supported there, but idk how good a solution that is tbf. Also can't find any other regex search extension that does exactly what this one does. Would really appreciate the update to MV3 :)

Redflashx12 avatar Mar 27 '25 10:03 Redflashx12

I've largely stepped away from this project since I don't have much time to maintain it these days. With that said, I'll happily merge and release this if the manifests for chrome and firefox are both updated to v3.

brandon1024 avatar Mar 27 '25 11:03 brandon1024

Mozilla also supports MV3 already, see e.g. this: https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/

Redflashx12 avatar Mar 27 '25 11:03 Redflashx12

@gers1978 would you be willing to migrate the firefox manifest to V3 as well? Once done, I'll merge.

brandon1024 avatar Mar 27 '25 11:03 brandon1024

Well, the current code has no working "service_worker", so the extension does not work. I think the "background.service_worker": [ ... ] part is wrong.

pzhlkj6612 avatar Apr 19 '25 12:04 pzhlkj6612

Finally, I think I've reached there. @brandon1024, please directly apply my patch onto this PR, then test the functions of our new MV3 extension.

Patch

Patch

From c06a3609e3092a4f66d95c9ea72af948273a6bad Mon Sep 17 00:00:00 2001
From: Mozi <[email protected]>
Date: Sun, 20 Apr 2025 14:19:46 +0000
Subject: [PATCH] Conform to BEAUTIFUL Manifest V3

Also make git-diff more readable.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

thought this migration would be that easy??

* https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/
* https://developer.chrome.com/docs/extensions/develop/migrate

NO.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

URL patterns of permissions:

* https://stackoverflow.com/questions/66851301/permission-all-urls-is-unknown-or-url-pattern-is-malformed

"executeScript()":

* https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript
* https://developer.chrome.com/docs/extensions/reference/api/scripting#method-executeScript
* https://stackoverflow.com/questions/66772626/chrome-scripting-executescript-not-working-in-my-manifest-v3-chrome-extension

API changes:

* https://developer.chrome.com/docs/extensions/reference/api/runtime#method-getURL
* https://stackoverflow.com/questions/32344868/chrome-runtime-geturl-vs-chrome-extension-geturl

Background service worker:

* https://developer.chrome.com/docs/extensions/develop/concepts/service-workers/basics
* https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background

* https://stackoverflow.com/questions/73440104/failing-to-export-to-background-js-from-a-common-script-under-firefox-with-mv3
* https://stackoverflow.com/questions/73421706/how-to-reuse-a-javascript-function-between-content-script-and-service-worker-in

* https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
* https://stackoverflow.com/questions/66055882/chrome-extensions-use-the-background-service-worker-key-instead-manifest-vers
* https://stackoverflow.com/questions/66406672/how-do-i-import-scripts-into-a-service-worker-using-chrome-extension-manifest-ve
* https://stackoverflow.com/questions/67980170/chrome-extension-background-script-into-multiple-scripts-manifest-v3

* https://stackoverflow.com/questions/70715942/chrome-extension-manifest-v3-libraries-in-background
* https://stackoverflow.com/questions/68194103/error-in-event-handler-referenceerror-window-is-not-defined-chrome-extension-w
* https://stackoverflow.com/questions/73778202/using-window-globals-in-manifestv3-service-worker-background-script

"background.service_worker is currently disabled" in Firefox:

* https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts
* https://stackoverflow.com/questions/75043889/manifest-v3-background-scripts-service-worker-on-firefox
* https://github.com/mozilla/web-ext/issues/2532

Unused references:

* https://stackoverflow.com/questions/48104433/how-to-import-es6-modules-in-content-script-for-chrome-extension
* https://stackoverflow.com/questions/60073155/how-to-edit-generated-background-page-html-page
---
 app.js                        |  2 +-
 background/_worker_wrapper.js |  5 +++
 background/background.js      | 10 +++---
 background/content-proxy.js   |  4 +--
 manifest.json                 | 67 ++++++++++++++++-------------------
 manifest_firefox.json         | 16 ++++++---
 6 files changed, 54 insertions(+), 50 deletions(-)
 create mode 100644 background/_worker_wrapper.js

diff --git a/app.js b/app.js
index 4538fca..17d9995 100644
--- a/app.js
+++ b/app.js
@@ -10,7 +10,7 @@ const Find = (function () {
     const self = {};
 
     self.browserId = (() => {
-        if(typeof window.browser !== 'undefined') {
+        if(typeof browser !== 'undefined') {
             return 'Firefox';
         } else {
             return 'Chrome';
diff --git a/background/_worker_wrapper.js b/background/_worker_wrapper.js
new file mode 100644
index 0000000..3f295fe
--- /dev/null
+++ b/background/_worker_wrapper.js
@@ -0,0 +1,5 @@
+importScripts('../app.js');
+importScripts('./browser-action-proxy.js');
+importScripts('./content-proxy.js');
+importScripts('./background.js');
+importScripts('./omni.js');
diff --git a/background/background.js b/background/background.js
index 62326f4..00b2698 100644
--- a/background/background.js
+++ b/background/background.js
@@ -21,13 +21,13 @@ Find.register("Background", function(self) {
     Find.browser.contextMenus.removeAll(() => {
         Find.browser.contextMenus.create({
             title: "Show Help",
-            contexts: ["browser_action"],
+            contexts: ["action"],
             id: 'show-help'
         });
 
         Find.browser.contextMenus.onClicked.addListener((info) => {
             if(info.menuItemId === 'show-help') {
-                Find.browser.tabs.create({url: Find.browser.extension.getURL("docs/index.html")});
+                Find.browser.tabs.create({url: Find.browser.runtime.getURL("docs/index.html")});
             }
         });
     });
@@ -47,15 +47,13 @@ Find.register("Background", function(self) {
                         continue;
                     }
 
-                    for (let i = 0; i < scripts.length; i++) {
-                        Find.Background.ContentProxy.executeScript(tabs[tabIndex], {file: scripts[i]});
-                    }
+                    Find.Background.ContentProxy.executeScript(tabs[tabIndex], {files: scripts});
                 }
             });
         }
 
         if(installation.reason === 'install') {
-            Find.browser.tabs.create({url: Find.browser.extension.getURL("docs/index.html")});
+            Find.browser.tabs.create({url: Find.browser.runtime.getURL("docs/index.html")});
         }
     });
 
diff --git a/background/content-proxy.js b/background/content-proxy.js
index f663c09..7e42af5 100644
--- a/background/content-proxy.js
+++ b/background/content-proxy.js
@@ -142,11 +142,11 @@ Find.register("Background.ContentProxy", function(self) {
      * Execute a given script in a specific tab.
      *
      * @param {object} tab - The tab with the search.
-     * @param {object} details - Details of the script to run. Either the code or the file property must be set, but
+     * @param {object} details - Details of the script to run. Either the func or the files property must be set, but
      * both may not be set at the same time.
      * @param {function} [callback] - Callback invoked once the operation is complete.
      * */
     self.executeScript = function(tab, details, callback) {
-        Find.browser.tabs.executeScript(tab.id, details, callback);
+        Find.browser.scripting.executeScript({target: {tabId: tab.id}, ...details}, callback);
     };
 });
\ No newline at end of file
diff --git a/manifest.json b/manifest.json
index 0a7969f..254dffc 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,55 +1,50 @@
 {
-  "manifest_version": 3,
   "name": "__MSG_extension_name__",
   "short_name": "find+",
   "version": "1",
   "author": ["Michael Walz", "Brandon Richardson"],
+  "manifest_version": 3,
   "description": "__MSG_extension_description__",
   "default_locale": "en",
-
-  "icons": {
-    "128": "resources/icon.png",
-    "16": "resources/icon.png",
-    "48": "resources/icon.png"
-  },
-
-  "host_permissions": [
-    "<all_urls>"
-  ],
-
   "permissions": [
     "tabs",
     "activeTab",
     "background",
     "storage",
-    "contextMenus"
+    "contextMenus",
+    "scripting"
+  ],
+  "host_permissions": [
+    "<all_urls>"
   ],
-
+  "icons": {
+    "128": "resources/icon.png",
+    "16": "resources/icon.png",
+    "48": "resources/icon.png"
+  },
   "action": {
-    "default_icon": "resources/icon.png",
+    "default_icon": {
+      "128": "resources/icon.png",
+      "16": "resources/icon.png",
+      "48": "resources/icon.png"
+    },
     "default_popup": "popup/popup.html"
   },
-  "background.service_worker": [
-    "app.js",
-    "/background/browser-action-proxy.js",
-    "/background/content-proxy.js",
-    "/background/background.js",
-    "/background/omni.js"
-  ],
-  "content_scripts": [
-    {
-      "matches": ["<all_urls>"],
-      "all_frames": false,
-      "run_at": "document_end",
-      "js": [
-        "app.js",
-        "/lib/html-entity-handler/entityhandler.js",
-        "/content/content.js",
-        "/content/parser.js",
-        "/content/highlighter.js"
-      ]
-    }
-  ],
+  "background": {
+    "service_worker": "/background/_worker_wrapper.js"
+  },
+  "content_scripts": [{
+    "matches": ["<all_urls>"],
+    "all_frames": false,
+    "run_at": "document_end",
+    "js": [
+      "app.js",
+      "/lib/html-entity-handler/entityhandler.js",
+      "/content/content.js",
+      "/content/parser.js",
+      "/content/highlighter.js"
+    ]
+  }],
   "omnibox": {
     "keyword" : "find"
   },
diff --git a/manifest_firefox.json b/manifest_firefox.json
index 2ca09a1..86f7647 100644
--- a/manifest_firefox.json
+++ b/manifest_firefox.json
@@ -3,14 +3,16 @@
   "short_name": "find+",
   "version": "1",
   "author": "Brandon Richardson, Michael Walz",
-  "manifest_version": 2,
+  "manifest_version": 3,
   "description": "__MSG_extension_description__",
   "default_locale": "en",
   "permissions": [
     "tabs",
     "activeTab",
     "storage",
-    "contextMenus",
+    "contextMenus"
+  ],
+  "host_permissions": [
     "<all_urls>"
   ],
   "icons": {
@@ -18,8 +20,12 @@
     "16": "resources/icon.png",
     "48": "resources/icon.png"
   },
-  "browser_action": {
-    "default_icon": "resources/icon.png",
+  "action": {
+    "default_icon": {
+      "128": "resources/icon.png",
+      "16": "resources/icon.png",
+      "48": "resources/icon.png"
+    },
     "default_popup": "popup/popup.html"
   },
   "background": {
@@ -47,7 +53,7 @@
     "keyword" : "find"
   },
   "commands": {
-    "_execute_browser_action": {
+    "_execute_action": {
       "suggested_key": {
         "default": "Ctrl+Shift+F",
         "mac": "MacCtrl+Shift+F"
-- 
2.34.1

References

References

URL patterns of permissions:

  • google chrome extension - Permission '<all_urls>' is unknown or URL pattern is malformed - Stack Overflow https://stackoverflow.com/q/66851301

"executeScript()":

  • scripting.executeScript() - Mozilla | MDN https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript
  • executeScript() § chrome.scripting  |  API  |  Chrome for Developers https://developer.chrome.com/docs/extensions/reference/api/scripting#method-executeScript
  • chrome.scripting.executeScript not working in my manifest v3 Chrome Extension - Stack Overflow https://stackoverflow.com/q/66772626

API changes:

  • getURL() § chrome.runtime  |  API  |  Chrome for Developers https://developer.chrome.com/docs/extensions/reference/api/runtime#method-getURL
  • javascript - chrome.runtime.getURL vs. chrome.extension.getURL - Stack Overflow https://stackoverflow.com/q/32344868

Background service worker:

  • Extension service worker basics  |  Chrome Extensions  |  Chrome for Developers https://developer.chrome.com/docs/extensions/develop/concepts/service-workers/basics

  • background - Mozilla | MDN https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background

  • javascript - Failing to export to background.js from a common script under Firefox with MV3 - Stack Overflow https://stackoverflow.com/q/73440104

  • google chrome extension - How to reuse a javascript function between content script and service worker in MV2/MV3-compatible way? - Stack Overflow https://stackoverflow.com/q/73421706

  • WorkerGlobalScope: importScripts() method - Web APIs | MDN https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts

  • Chrome extensions: Use the "background.service_worker" key instead manifest_version 3 - Stack Overflow https://stackoverflow.com/q/66055882

  • How do I import scripts into a service worker using Chrome extension manifest version 3? - Stack Overflow https://stackoverflow.com/q/66406672

  • Chrome extension background script into multiple scripts - manifest v3 - Stack Overflow https://stackoverflow.com/q/67980170

  • javascript - Chrome Extension Manifest V3 Libraries in Background - Stack Overflow https://stackoverflow.com/q/70715942

  • Error in event handler: ReferenceError: window is not defined chrome extension with manifest v3 - Stack Overflow https://stackoverflow.com/q/68194103

  • google chrome extension - Using window globals in ManifestV3 service worker background script - Stack Overflow https://stackoverflow.com/q/73778202

"background.service_worker is currently disabled" in Firefox:

  • Background scripts - Mozilla | MDN https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts
  • google chrome - Manifest v3 background scripts/service worker on Firefox - Stack Overflow https://stackoverflow.com/q/75043889
  • Manifest Version 3 background.Service_Worker is currently disabled · Issue #2532 · mozilla/web-ext https://github.com/mozilla/web-ext/issues/2532

Unused references:

  • javascript - How to import ES6 modules in content script for Chrome Extension - Stack Overflow https://stackoverflow.com/q/48104433
  • google chrome extension - How to edit _generated_background_page.html page? - Stack Overflow https://stackoverflow.com/q/60073155

.

pzhlkj6612 avatar Apr 20 '25 14:04 pzhlkj6612

Ping @brandon1024: hey, we now have only little time:

Starting in June, the branch for Chrome 139 will begin, in which support for Manifest V2 extensions will be removed from Chrome.

from: https://developer.chrome.com/docs/extensions/develop/migrate/mv2-deprecation-timeline

Chrome Dev for Android Update

Thursday, June 19, 2025

Hi everyone! We've just released Chrome Dev 139 (139.0.7246.0) for Android. It's now available on Google Play.

from: https://chromereleases.googleblog.com/2025/06/chrome-dev-for-android-update_19.html

.

pzhlkj6612 avatar Jun 20 '25 04:06 pzhlkj6612

I've recently had the find+ extension removed from Chrome due to the Manifest V3 issue.

@brandon1024, I understand your desire to bring both versions (Chrome and Firefox) at V3 to keep things in sync, but considering that Firefox has no plan to depreciate V2, perhaps this could be done in a seperate PR. Firefox users are unaffected by all these V3 issues, but the problem is real on Chrome in the meantime.

@pzhlkj6612, I think your suggested changes would have a much better chance of being merged if you created a seperate PR for them. GitHub allows to checkout branches from other forks, so you could commit your changes on top of the ones in this PR. This is not the Linux kernel mailing list after all 😅

DecimalTurn avatar Jul 18 '25 03:07 DecimalTurn

Any update to this? I'm missing this amazing extension. 😊️

transformd avatar Jul 31 '25 18:07 transformd