0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

自作のChrome拡張機能をManifest V3へ移行した際の修正内容まとめ

Posted at

自作のChrome拡張機能

Chord Dictionary

修正内容

manifest.json

manifest.json
{
- "manifest_version": 2,
+ "manifest_version": 3,
  "web_accessible_resources": [
-    "main.js",
-    "main.css",
+    {
+      "resources": ["main.js", "main.css", "sounds/*.mp3"],
+      "matches": ["http://*/*", "https://*/*"]
+    }
  ],
-  "browser_action": {
+  "action": {
    "default_title": "Chord Dictionary"
  },
  ],
  "background": {
-    "scripts": [
-      "background.js"
-    ],
-    "persistent": false
+    "service_worker": "background.js"
  },
  "permissions": [
    "tabs",
    "activeTab",
    "storage"
+    "scripting"
  ]
}

関数

chrome.browserAction

chrome.browserActionchrome.actionにする

- chrome.browserAction.onClicked.addListener(function (tab) {
+ chrome.action.onClicked.addListener((tab) => {
- chrome.browserAction.setBadgeText({ text: isActiveTo ? "ON" : "" });
+ chrome.action.setBadgeText({ text: isActiveTo ? "ON" : "" });

chrome.tabs.executeScript、chrome.tabs.insertCSS

chrome.tabs.executeScriptchrome.scripting.executeScriptにする

- chrome.tabs.executeScript(tabId, { file: "main.js" });
+ chrome.scripting.executeScript({
+   target: { tabId: tabId },
+   files: ["main.js"],
+ });

chrome.tabs.insertCSSchrome.scripting.insertCSSにする

- chrome.tabs.insertCSS(tabId, { file: "main.css" });
+ chrome.scripting.insertCSS({
+   target: { tabId: tabId },
+   files: ["main.css"],
+ });

manifest.jsonpermissionsscriptingを追加する必要がある

chrome.extension.getURL

chrome.extensionchrome.runtimeにする

- chrome.extension.getURL("sounds/piano-c2.mp3")
+ chrome.runtime.getURL("sounds/piano-c2.mp3")

参考

その他に必要な修正は公式のマイグレーションガイドが参考になります。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?