{"id":2082,"date":"2024-07-27T15:24:47","date_gmt":"2024-07-27T07:24:47","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=2082"},"modified":"2024-07-27T15:25:58","modified_gmt":"2024-07-27T07:25:58","slug":"v3-ban-ben-de-chrome-kuo-zhan-xiang-mu-mo-ban","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=2082","title":{"rendered":"V3 \u7248\u672c\u7684 Chrome \u6269\u5c55\u9879\u76ee\u6a21\u677f"},"content":{"rendered":"<p>\u8981\u521d\u59cb\u5316\u4e00\u4e2a\u57fa\u4e8e Chrome \u6269\u5c55\u7684\u9879\u76ee\uff0c\u5305\u62ec V3 \u7248\u672c\uff0c\u4f60\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u9879\u76ee\u6587\u4ef6\u5939\uff1a<\/strong> \u5728\u4f60\u7684\u9879\u76ee\u6587\u4ef6\u5939\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\u5939\u6765\u4fdd\u5b58\u4f60\u7684\u6269\u5c55\u4ee3\u7801\u548c\u8d44\u6e90\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u6e05\u5355\u6587\u4ef6\uff08manifest.json\uff09\uff1a<\/strong> Chrome \u6269\u5c55\u7684\u6838\u5fc3\u662f\u6e05\u5355\u6587\u4ef6\uff0c\u5b83\u63cf\u8ff0\u4e86\u6269\u5c55\u7684\u5c5e\u6027\u3001\u6743\u9650\u548c\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684 V3 \u7248\u672c\u6e05\u5355\u6587\u4ef6\u793a\u4f8b\uff1a<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-json\">{\n  &quot;manifest_version&quot;: 3,\n  &quot;name&quot;: &quot;My Extension&quot;,\n  &quot;version&quot;: &quot;1.0&quot;,\n  &quot;description&quot;: &quot;A description of my extension.&quot;,\n  &quot;permissions&quot;: [\n    &quot;activeTab&quot;\n  ],\n  &quot;content_scripts&quot;: [\n    {\n      &quot;matches&quot;: [&quot;&lt;all_urls&gt;&quot;],\n      &quot;js&quot;: [&quot;content.js&quot;]\n    }\n  ],\n  &quot;background&quot;: {\n    &quot;service_worker&quot;: &quot;background.js&quot;\n  },\n  &quot;action&quot;: {\n    &quot;default_popup&quot;: &quot;popup.html&quot;,\n    &quot;default_icon&quot;: {\n      &quot;16&quot;: &quot;images\/icon16.png&quot;,\n      &quot;48&quot;: &quot;images\/icon48.png&quot;,\n      &quot;128&quot;: &quot;images\/icon128.png&quot;\n    }\n  },\n  &quot;icons&quot;: {\n    &quot;16&quot;: &quot;images\/icon16.png&quot;,\n    &quot;48&quot;: &quot;images\/icon48.png&quot;,\n    &quot;128&quot;: &quot;images\/icon128.png&quot;\n  }\n}\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>\u6dfb\u52a0\u6269\u5c55\u56fe\u6807\u548c\u8d44\u6e90\uff1a<\/strong> \u5728\u9879\u76ee\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a &quot;images&quot; \u6587\u4ef6\u5939\uff0c\u5c06\u4f60\u7684\u6269\u5c55\u56fe\u6807\uff0816&#215;16\u300148&#215;48 \u548c 128&#215;128 \u5927\u5c0f\uff09\u653e\u5165\u5176\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u5199\u5185\u5bb9\u811a\u672c\uff08content.js\uff09\uff1a<\/strong> \u8fd9\u662f\u5728\u7f51\u9875\u5185\u5bb9\u4e2d\u6267\u884c\u7684\u811a\u672c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\">\/\/ content.js\nconsole.log(&quot;Content script loaded!&quot;);\n<\/code><\/pre>\n<ol start=\"5\">\n<li><strong>\u7f16\u5199\u80cc\u666f\u811a\u672c\uff08background.js\uff09\uff1a<\/strong> \u8fd9\u662f\u5728\u540e\u53f0\u8fd0\u884c\u7684\u811a\u672c\uff0c\u53ef\u4ee5\u76d1\u542c\u4e8b\u4ef6\u548c\u5904\u7406\u903b\u8f91\u3002<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\">\/\/ background.js\nconsole.log(&quot;Background script loaded!&quot;);\n\nchrome.action.onClicked.addListener((tab) =&gt; {\n  chrome.scripting.executeScript({\n    target: {tabId: tab.id},\n    function: () =&gt; {\n      console.log(&quot;Script executed on the active tab.&quot;);\n    }\n  });\n});\n<\/code><\/pre>\n<ol start=\"6\">\n<li><strong>\u521b\u5efa\u5f39\u51fa\u9875\u9762\uff08popup.html\uff09\uff1a<\/strong> \u8fd9\u662f\u70b9\u51fb\u6269\u5c55\u56fe\u6807\u65f6\u663e\u793a\u7684\u5f39\u51fa\u9875\u9762\u3002<\/li>\n<\/ol>\n<pre><code class=\"language-html\">&lt;!-- popup.html --&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n  &lt;title&gt;My Extension Popup&lt;\/title&gt;\n  &lt;script src=&quot;popup.js&quot;&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;h1&gt;Hello from the popup!&lt;\/h1&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<ol start=\"7\">\n<li><strong>\u7f16\u5199\u5f39\u51fa\u9875\u9762\u811a\u672c\uff08popup.js\uff09\uff1a<\/strong><\/li>\n<\/ol>\n<pre><code class=\"language-javascript\">\/\/ popup.js\nconsole.log(&quot;Popup script loaded!&quot;);\n<\/code><\/pre>\n<ol start=\"8\">\n<li>\n<p><strong>\u52a0\u8f7d\u6269\u5c55\uff1a<\/strong><\/p>\n<ul>\n<li>\u6253\u5f00 Chrome \u6d4f\u89c8\u5668\uff0c\u8f93\u5165 <code>chrome:\/\/extensions\/<\/code> \u5e76\u6309\u4e0b Enter\u3002<\/li>\n<li>\u5728\u53f3\u4e0a\u89d2\u542f\u7528 &quot;\u5f00\u53d1\u8005\u6a21\u5f0f&quot;\u3002<\/li>\n<li>\u70b9\u51fb &quot;\u52a0\u8f7d\u5df2\u89e3\u538b\u7684\u6269\u5c55\u7a0b\u5e8f&quot;\uff0c\u9009\u62e9\u4f60\u7684\u9879\u76ee\u6587\u4ef6\u5939\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6d4b\u8bd5\u6269\u5c55\uff1a<\/strong> \u73b0\u5728\u4f60\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u6d4b\u8bd5\u4f60\u7684\u6269\u5c55\u4e86\u3002\u70b9\u51fb\u6269\u5c55\u56fe\u6807\uff0c\u5f39\u51fa\u9875\u9762\u5e94\u8be5\u4f1a\u663e\u793a &quot;Hello from the popup!&quot;\uff0c\u5e76\u4e14\u5728\u5f00\u53d1\u8005\u5de5\u5177\u7684\u63a7\u5236\u53f0\u4e2d\u4f1a\u770b\u5230\u76f8\u5173\u7684\u65e5\u5fd7\u8f93\u51fa\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u6b65\u9aa4\u4e3a\u521d\u59cb\u5316\u4e00\u4e2a\u57fa\u4e8e Chrome \u6269\u5c55 V3 \u7248\u672c\u7684\u9879\u76ee\u6240\u9700\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u6839\u636e\u4f60\u7684\u6269\u5c55\u529f\u80fd\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u6dfb\u52a0\u66f4\u591a\u7684\u529f\u80fd\u548c\u6587\u4ef6\u3002\u8bb0\u5f97\u67e5\u9605 Chrome \u5f00\u53d1\u8005\u6587\u6863\u4ee5\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u521d\u59cb\u5316\u4e00\u4e2a\u57fa\u4e8e Chrome \u6269\u5c55\u7684\u9879\u76ee\uff0c\u5305\u62ec V3 \u7248\u672c\uff0c\u4f60\u9700\u8981\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a \u521b\u5efa\u9879\u76ee&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,20,3],"tags":[261,262],"class_list":["post-2082","post","type-post","status-publish","format-standard","hentry","category-all","category-frontend","category-tech","tag-chrome","tag-extension"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/2082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2082"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/2082\/revisions"}],"predecessor-version":[{"id":2083,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/2082\/revisions\/2083"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}