{"id":107908,"date":"2023-02-24T09:29:22","date_gmt":"2023-02-24T00:29:22","guid":{"rendered":"https:\/\/softantenna.com\/blog\/?p=107908"},"modified":"2023-02-24T09:29:22","modified_gmt":"2023-02-24T00:29:22","slug":"chrome-extension-manifest-v3","status":"publish","type":"post","link":"https:\/\/softantenna.com\/blog\/chrome-extension-manifest-v3\/","title":{"rendered":"Chrome\u62e1\u5f35\u6a5f\u80fd\u3092\u300cManifest V3\u300d\u306b\u5bfe\u5fdc\u3059\u308b\u624b\u9806"},"content":{"rendered":"<p><img decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https:\/\/softantenna.com\/blog\/wp-content\/uploads\/2023\/02\/s_20230223_173512.jpg\" alt=\"S 20230223 173512\" title=\"s_20230223_173512.jpg\" border=\"0\" width=\"964\" height=\"482\" \/><\/p>\n<p>Google\u306f\u73fe\u5728\u3001Chrome\u306e\u62e1\u5f35\u6a5f\u80fd\u306e\u4ed5\u69d8\u3092\u300cManifest V3\u300d\u3078\u79fb\u884c\u3059\u308b\u305f\u3081\u306e<a href=\"https:\/\/developer.chrome.com\/blog\/more-mv2-transition\/\">\u8a08\u753b<\/a>\u3092\u9032\u3081\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>2023\u5e741\u6708\u306bManifest V3\u304c\u300cFeatured\u300d\u30d0\u30c3\u30b8\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u5fc5\u9808\u6761\u4ef6\u3068\u306a\u308a(\u306e\u3061\u306b\u5ef6\u671f)\u30012023\u5e746\u6708\u3088\u308aChrome \u30a6\u30a7\u30d6\u30b9\u30c8\u30a2\u3067Manifest V2\u3092\u4f7f\u7528\u3057\u305f\u62e1\u5f35\u6a5f\u80fd\u306e\u53ef\u8996\u6027\u3092\u300c\u516c\u958b\u300d\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u304f\u306a\u308b\u306a\u3069\u3001\u79fb\u884c\u306b\u5411\u3051\u305f\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u304c\u7acb\u3066\u3089\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308d\u305d\u308dManifest V3\u3078\u306e\u79fb\u884c\u3092\u8003\u3048\u3066\u3044\u308b\u65b9\u306e\u305f\u3081\u3001\u4eca\u56de\u306f\u81ea\u4f5c\u306eChrome\u306e\u62e1\u5f35\u6a5f\u80fd\u3001\u300c<a href=\"https:\/\/chrome.google.com\/webstore\/detail\/feedly-star-opener\/hecknmjndpndohooejpacafgliphbbop?hl=ja\">Feedly Star Opener<\/a>\u300d\u3092Manifest V3\u306b\u79fb\u884c\u3059\u308b\u305f\u3081\u306b\u884c\u3063\u305f\u4f5c\u696d\u3092\u307e\u3068\u3081\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>Manifest V3\u5bfe\u5fdc\u4f5c\u696d<\/h2>\n<p>\u4f5c\u696d\u306b\u3042\u305f\u308a\u4ee5\u4e0b\u306e\u30b5\u30a4\u30c8\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/qiita.com\/TiggeZaki\/items\/bb35afe43c347d38dc4e\">\u81ea\u4f5c\u306eChrome\u62e1\u5f35\u6a5f\u80fd\u3092ManifestV3\u306b\u79fb\u884c\u3057\u3066\u307f\u305f - Qiita<\/a><\/li>\n<li><a href=\"https:\/\/memo.furyutei.com\/entry\/20221002\/1664638665\">Chrome\u62e1\u5f35\u6a5f\u80fdManifest V3\u5bfe\u5fdc\u306e\u52d8\u3069\u3053\u308d(?) - \u98a8\u67f3\u30e1\u30e2<\/a><\/li>\n<\/ul>\n<p>\u7d50\u679c\u7684\u306bmanifest.json\u3001background.js\u3001optins.js\u3092\u4fee\u6b63\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u305d\u308c\u305e\u308c\u306e\u5909\u66f4\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059(\u5909\u66f4\u5f8c\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u5168\u4f53\u306f<a href=\"https:\/\/github.com\/src256\/feedly-star-opener-ext\">GitHub<\/a>\u3067\u78ba\u8a8d\u53ef\u80fd\u3067\u3059)\u3002<\/p>\n<h3>manifest.json\u306e\u5909\u66f4<\/h3>\n<p>manifest_version\u30923\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\"manifest_version\": 3,<\/code><\/pre>\n<\/div>\n<p>js\/background.js\u304b\u3089background.js\u306b\u5909\u66f4\u3057\u307e\u3059\u3002background.js\u30d5\u30a1\u30a4\u30eb\u81ea\u4f53\u306e\u5834\u6240\u3082\u79fb\u52d5\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\"background\": {\r\n        \"service_worker\": \"background.js\"\r\n},<\/code><\/pre>\n<\/div>\n<p>permissions\u3092\u5909\u66f4\u3057\u307e\u3059\u3002\u30db\u30b9\u30c8\u6bce\u306e\u8a31\u53ef\u306fhost_permissions\u306b\u79fb\u52d5\u3057\u3001chrome.storage.local\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3067\u3066\u304d\u305f\u306e\u3067\u3001permissions\u306bstorage\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>    \"permissions\": [\r\n\t    \"storage\"\r\n    ],\r\n    \"host_permissions\": [\r\n        \"http:\/\/feedly.com\/*\",\r\n        \"https:\/\/feedly.com\/*\"\r\n    ],<\/code><\/pre>\n<\/div>\n<h3>optins.js\u306e\u5909\u66f4<\/h3>\n<p>options.js\u3067\u306f\u3053\u308c\u307e\u3067background.js\u306e\u95a2\u6570\u3092\u76f4\u63a5\u547c\u3073\u51fa\u3057\u3066\u30c7\u30fc\u30bf\u306e\u8aad\u4fdd\u5b58\u3092\u884c\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>Manifest V3\u3067\u306fchrome.extension.getBackgroundPage()\u304c\u4f7f\u3048\u306a\u304f\u306a\u308a\u3001options.js\u304b\u3089background.js\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u305f\u308a\u5909\u6570\u3092\u53c2\u7167\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>contentscripts.js\u306e\u3088\u3046\u306bsendMessage\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u306e\u3084\u308a\u3068\u308a\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u4fdd\u5b58\u7528\u306b\"setOptions\"\u3092\u547c\u3073\u51fa\u3057\u307e\u3059(\u65b0\u8a2d)\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>    $(\"#save\").on('click', function() {\r\n\t\t\/\/\u30d5\u30a9\u30fc\u30e0\u306b\u5165\u529b\u3055\u308c\u305f\u5024\u3092\u6b63\u898f\u5316\u3057\u3066\u53cd\u6620\r\n\t\tvar tabcount = $(\"#fso_tabcount\").val();\r\n\t\t\/\/ \/\/\u6b63\u898f\u5316\u5f8c\u306e\u5024\u3092\u30ed\u30fc\u30ab\u30eb\u30b9\u30c8\u30ec\u30fc\u30b8\u306b\u4fdd\u5b58\r\n\t\t\/\/ chrome.storage.local.set({bg.FSO_TABCOUNT_KEY : tabcount}, function () {});\r\n\t\tchrome.runtime.sendMessage({method: \"setOptions\", tabcount: tabcount}, function() {\r\n\t\t\t\/\/ console.log(\"ok\");\r\n\t\t});\r\n    });\r\n<\/code><\/pre>\n<\/div>\n<p>\u30c7\u30fc\u30bf\u53d6\u5f97\u7528\u306e\u51e6\u7406\u306f\u3082\u3068\u3082\u3068sendMessage\u3092\u4f7f\u3063\u3066\u3044\u305f\u306e\u3067\u3042\u307e\u308a\u5909\u66f4\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3053\u308c\u306fcontentscripts.js\u3068\u306e\u51e6\u7406\u306e\u5171\u901a\u5316\u306e\u305f\u3081\u3067\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\tchrome.runtime.sendMessage({method: \"getOptions\"}, function(response) {\r\n\t\tvar tabcount = response.fso_tabcount;\r\n\t\tupdate_form_tabcount(tabcount);\r\n\t});\r\n<\/code><\/pre>\n<\/div>\n<h3>background.js\u306e\u5909\u66f4<\/h3>\n<p>options.js\u304b\u3089\u547c\u3073\u51fa\u3055\u308c\u308bsetOptions\u306e\u51e6\u7406\u3092\u65b0\u8a2d\u3057\u307e\u3059\u3002\u3053\u308c\u307e\u3067\u8a2d\u5b9a\u5024\u306e\u4fdd\u5b58\u306b\u4f7f\u3063\u3066\u3044\u305flocalStorage\u304c\u4f7f\u3048\u306a\u304f\u306a\u3063\u305f\u306e\u3067chrome.storage.local\u306b\u66f8\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<p>chrome.storage.local\u306f\u51e6\u7406\u304c\u975e\u540c\u671f\u306a\u306e\u3067\u306f\u307e\u308a\u3084\u3059\u3044\u3067\u3059\u3002\u307e\u305fchrome.runtime.onMessage.addListener\u5185\u306e\u51e6\u7406\u3067\u6700\u5f8c\u306b\u300creturn true\u300d\u3092\u8ffd\u52a0\u3057\u306a\u3044\u3068\u3046\u307e\u304f\u3044\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>var FSO_TABCOUNT_DEF = 8;\r\n\r\nfunction normalized_fso_tabcount(raw_value) {\r\n    var tabcount = parseInt(raw_value);\r\n    if (isNaN(tabcount) || tabcount <= 0 || tabcount > 20) {\r\n        \/\/\u30a8\u30e9\u30fc\u306e\u5834\u5408\u306f\u898f\u5b9a\u5024\r\n        tabcount = FSO_TABCOUNT_DEF;\r\n    }\r\n    \/\/\u6570\u5024\u578b\r\n    return tabcount;\r\n}\r\n\r\n\r\nchrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {\r\n    if (request.method == \"getOptions\") {\r\n\t    var raw_tabcount = null;\r\n\t    chrome.storage.local.get(\"fso_tabcount\", function (value) {\r\n\t        raw_tabcount = value.fso_tabcount;\r\n            var tabcount = normalized_fso_tabcount(raw_tabcount);\r\n            sendResponse({fso_tabcount: tabcount});    \r\n\t    });\r\n        return true;\r\n    } else if (request.method == \"setOptions\") {\r\n        var tabcount = normalized_fso_tabcount(request.tabcount);\r\n        chrome.storage.local.set({\"fso_tabcount\": tabcount} , function () {\r\n            sendResponse({farewell: \"goodbye\"});\r\n\/\/            chrome.storage.local.get(\"fso_tabcount\", function (value) {\r\n\/\/                console.log(\"get=\" + value.fso_tabcount);\r\n\/\/            }); \r\n        });\r\n        return true;\r\n    } else {\r\n        sendResponse({});\r\n        return true;\r\n    }\r\n});\r\n<\/code><\/pre>\n<\/div>\n<h3>contentscripts.js<\/h3>\n<p>contentscripts.js\u306b\u5909\u66f4\u70b9\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<h3>Chrome Web Store\u3067\u66f4\u65b0<\/h3>\n<p>Chrome Web Store\u3067\u306e\u4f5c\u696d\u306f\u901a\u5e38\u6642\u3068\u5909\u308f\u308a\u3042\u308a\u307e\u305b\u3093\u304c\u3001permissions\u306bstorage\u3092\u8ffd\u52a0\u3057\u305f\u306e\u3067\u305d\u306e\u7406\u7531\u3092\u5165\u529b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\u3002\u4ed6\u306f\u7279\u306b\u554f\u984c\u306a\u304f\u66f4\u65b0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u767b\u9332\u5f8c\u5373\u516c\u958b\u3055\u308c\u305f\u306e\u306fManifest V3\u52b9\u679c\uff1f<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u81ea\u4f5cChrome\u62e1\u5f35\u6a5f\u80fd\u3092\u300cManifest V3\u300d\u306b\u5bfe\u5fdc\u3057\u305f\u624b\u9806\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002Manifest V3\u306e\u79fb\u884c\u3067\u6c17\u304c\u91cd\u304f\u306a\u3063\u3066\u3044\u308b\u65b9\u306e\u53c2\u8003\u306b\u306a\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google\u306f\u73fe\u5728\u3001Chrome\u306e\u62e1\u5f35\u6a5f\u80fd\u306e\u4ed5\u69d8\u3092\u300cManifest V3\u300d\u3078\u79fb\u884c\u3059\u308b\u305f\u3081\u306e\u8a08\u753b\u3092\u9032\u3081\u3066\u3044\u307e\u3059\u3002 2023\u5e741\u6708\u306bManifest V3\u304c\u300cFeatured\u300d\u30d0\u30c3\u30b8\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u5fc5\u9808\u6761\u4ef6\u3068\u306a\u308a(\u306e\u3061\u306b\u5ef6 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":107916,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[2047],"tags":[26],"class_list":["post-107908","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips","tag-chrome"],"_links":{"self":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/107908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/comments?post=107908"}],"version-history":[{"count":0,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/107908\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media\/107916"}],"wp:attachment":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media?parent=107908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/categories?post=107908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/tags?post=107908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}