{"id":10020402,"date":"2024-11-21T00:54:26","date_gmt":"2024-11-20T16:54:26","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020402"},"modified":"2024-11-21T00:54:26","modified_gmt":"2024-11-20T16:54:26","slug":"%e5%86%99%e4%b8%80%e4%b8%aachrome%e6%b5%8f%e8%a7%88%e5%99%a8%e6%8f%92%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020402","title":{"rendered":"\u5199\u4e00\u4e2aChrome\u6d4f\u89c8\u5668\u63d2\u4ef6"},"content":{"rendered":"<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u5de5\u4e1a \u7126\u4e01<\/p>\n<h2>\u4e00\u3001\u4ec0\u4e48\u662f\u6d4f\u89c8\u5668\u63d2\u4ef6<\/h2>\n<p>\u6d4f\u89c8\u5668\u63d2\u4ef6\u662f\u4f9d\u9644\u4e8e\u6d4f\u89c8\u5668\uff0c\u7528\u6765\u62d3\u5c55\u7f51\u9875\u80fd\u529b\u7684\u7a0b\u5e8f\u3002\u63d2\u4ef6\u5177\u6709\u76d1\u542c\u6d4f\u89c8\u5668\u4e8b\u4ef6\u3001\u83b7\u53d6\u548c\u4fee\u6539\u7f51\u9875\u5143\u7d20\u3001\u62e6\u622a\u7f51\u7edc\u8bf7\u6c42\u3001\u6dfb\u52a0\u5feb\u6377\u83dc\u5355\u7b49\u529f\u80fd\u3002\u4f7f\u7528\u6d4f\u89c8\u5668\u63d2\u4ef6\u53ef\u4ee5\u5b9e\u73b0\u5f88\u591a\u6709\u8da3\u7684\u529f\u80fd\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484268\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p>\n<h2>\u4e8c\u3001\u6d4f\u89c8\u5668\u63d2\u4ef6\u6709\u54ea\u4e9b\u79cd\u7c7b<\/h2>\n<p>\u2022\u4ee5chromium\u4e3a\u5185\u6838\u7684\u6d4f\u89c8\u5668\u63d2\u4ef6\u5982Chrome<\/p>\n<p>\u2022\ufefffirefox\u6d4f\u89c8\u5668\u63d2\u4ef6<\/p>\n<p>\u2022\ufeff\ufeffsafari\u6d4f\u89c8\u5668\u63d2\u4ef6<\/p>\n<p>\u672c\u6587\u53ea\u4ecb\u7ecdChrome\u63d2\u4ef6\u7684\u539f\u751f\u5f00\u53d1\u6d41\u7a0b\u3002<\/p>\n<h2>\u4e09\u3001\u63d2\u4ef6\u76ee\u5f55\u4ecb\u7ecd<\/h2>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484269\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<table>\n<thead>\n<tr>\n<th>a\u7684\u6587\u4ef6\u540d<\/th>\n<th>\u6587\u4ef6\u4ecb\u7ecd<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=%2B7igGEdmFX%2B7Plg%2F%2B7ykxA%3D%3D.2Nv8OM07Sndh45Vsm74cMFPJDfcnEgoZJelX0IlV2qKT%2FBtiQ2C6Ci7zkt2QyEwRzTs22Tc%2FV3MJMFFwKkdeJQQUDj60d7DpET2f20ltTms%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">manifest<\/a><\/td>\n<td>\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\uff0c\u914d\u7f6e\u63d2\u4ef6\u5e73\u53f0\u7248\u672c\u3001\u540d\u79f0\u3001<a href=\"https:\/\/link.segmentfault.com\/?enc=2h45dkv7y9edYnFPE2hAiw%3D%3D.23SGumeJzSukupvQ1pgasIaUAMNzcflLeokbKLBP3exgFNnRsy2z31siGXok3PrPGbObPoFL3tNBsmyXOXaiAaoJI%2F%2FuNhEfYm40PRQ42dq7Rptncac8MfLFQB48P4Q5\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u6743\u9650<\/a>\u3001Aicon\u3001<a href=\"https:\/\/link.segmentfault.com\/?enc=oTpTKlu87pE8vc3mJLIYfA%3D%3D.8Ah9UgbgO8RcfNNvWCkI4EdVsgTOaAgDJbjkKD7m5D9WPIdMomy8NNumCSQXjMJm4cmJU5wGXdkIl6ACe7b4eUL6U4mFJjrHxqbA7uvRmTY%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Api\u6743\u9650<\/a>\u3001host\u6743\u9650\u7b49\u3002<\/td>\n<\/tr>\n<tr>\n<td>popup.html<\/td>\n<td>\u63d2\u4ef6\u5f39\u51fa\u9875\u9762\uff0c\u539f\u751fhtml\u3001css\u9875\u9762\u3002<\/td>\n<\/tr>\n<tr>\n<td>popup.js<\/td>\n<td>\u63d2\u4ef6\u9875\u9762\u7684\u811a\u672c\u6587\u4ef6\u3002<\/td>\n<\/tr>\n<tr>\n<td>popup.css<\/td>\n<td>\u63d2\u4ef6\u9875\u9762\u7684\u6837\u5f0f\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>background.js<\/td>\n<td>\u540e\u53f0\u6587\u4ef6\uff0c\u53ef\u4ee5\u76d1\u542c\u6d4f\u89c8\u5668\u4e8b\u4ef6\uff0c\u5728\u6d4f\u89c8\u5668\u540e\u53f0\u6301\u7eed\u8fd0\u884c\u3002<\/td>\n<\/tr>\n<tr>\n<td><a href=\"https:\/\/link.segmentfault.com\/?enc=ZjSmPiwzMtVU4f9pToSSZA%3D%3D.XVIjYog%2BuAeF42QeGOROg2WxsCsgUwDUG2OIwIN%2FWy0T4YDYn8m7PcCIgagiYGkcn7OR4gDuwVD7Fn%2B%2BRsCiichB8jx23RrzGi3YFginlt440PCB9711xhdrVhNf4aVX\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">content.js<\/a><\/td>\n<td>\u63d2\u5165\u5230\u9875\u9762\u4e2d\u7684js\u811a\u672c\uff0c\u53ef\u4ee5\u76d1\u542cDOM\u4e8b\u4ef6\uff0c\u64cd\u4f5cDOM\u5143\u7d20\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u56db\u3001\u5f00\u59cb\u5199\u4e00\u4e2a\u63d2\u4ef6<\/h2>\n<h3>1. \u914d\u7f6emanifest\u3002<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u7840\u7684manifest\u914d\u7f6e<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484270\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h3>2. \u5199\u4e00\u4e2a\u63d2\u4ef6\u7684\u5f39\u6846\u754c\u9762popup.html<\/h3>\n<p>\u548c\u5199html\u9875\u9762\u4e00\u6837\uff0c\u5728body\u91cc\u9762\u5199\u5143\u7d20\uff0c\u4f46\u662f\u9700\u8981\u6ce8\u610f\u6837\u5f0f\u6587\u4ef6popup.css\u548c\u811a\u672c\u6587\u4ef6popup.js\u9700\u8981\u5916\u90e8\u5f15\u5165\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484271\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h3>3. \u5199\u4e00\u4e2a\u63d2\u4ef6\u5f39\u6846\u754c\u9762\u7684\u6837\u5f0f\u6587\u4ef6popup.css\u3002<\/h3>\n<h3>4. \u5199\u4e00\u4e2a\u63d2\u4ef6\u5f39\u6846\u754c\u9762\u7684\u811a\u672c\u6587\u4ef6popup.js\u3002<\/h3>\n<p>\u811a\u672c\u6587\u4ef6\u7684\u4e3b\u8981\u4f5c\u7528\u5728\u4e8e\u54cd\u5e94\u63d2\u4ef6\u5f39\u7a97\u7684\u884c\u4e3a\u4e8b\u4ef6\uff0c\u5e76\u53d1\u9001\u6d88\u606f\u7ed9\u5185\u5bb9\u811a\u672c\u6216\u8005\u540e\u53f0\u811a\u672c\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u662f\u5728popup.js\u4e2d\uff0c\u76d1\u542cid\u4e3atag\u5143\u7d20\u7684\u70b9\u51fb\u4e8b\u4ef6\uff0c\u83b7\u53d6\u5f53\u524d\u7a97\u53e3active\u6807\u7b7e\u9875\uff0c\u5e76\u7ed9\u6b64\u6807\u7b7e\u9875\u63a8\u9001\u4e00\u4e2amessage\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484272\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h3>4. \u5199\u4e00\u4e2a\u63d2\u4ef6\u7684\u5185\u5bb9\u811a\u672ccontent.js<\/h3>\n<p>content.js\u4f1a\u88ab\u63d2\u5165\u5230\u7f51\u9875\u73af\u5883\u4e2d\uff0c\u7528\u4e8e\u76d1\u542c\u6d4f\u89c8\u5668\u4e8b\u4ef6\uff0c\u8bfb\u53d6\u548c\u64cd\u4f5cDOM\u5143\u7d20\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u662f\u76d1\u542c\u9875\u9762load\u4e8b\u4ef6\uff0c\u548c\u63a5\u6536\u6765\u81ea\u7b2c\u4e09\u6b65\u4e2dsend\u7684message\u3002<\/p>\n<pre><code>\nwindow.addEventListener(&quot;load&quot;, function () {\n    \/\/ \u76d1\u542c\u9875\u9762load\u4e8b\u4ef6\n})\n\nchrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {\n console.log(&quot;-----------&quot;);\n if (request.greeting === &quot;tag&quot;) {\n    console.log(request.greeting)\n }\n});<\/code><\/pre>\n<h3>5. \u5199\u4e00\u4e2a\u63d2\u4ef6\u7684\u540e\u53f0\u811a\u672cbackground.js<\/h3>\n<p>\u540e\u53f0\u811a\u672c\u4f1a\u5728\u6d4f\u89c8\u5668\u7a97\u53e3\u6253\u5f00\u671f\u95f4\u6301\u7eed\u8fd0\u884c\uff0c\u76d1\u542c\u6d4f\u89c8\u5668\u4e8b\u4ef6\uff0c\u7f51\u7edc\u8bf7\u6c42\u7b49\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u662f\u6d4f\u89c8\u5668\u5c4f\u853d\u6f0f\u67d0\u4e9burl\u8bf7\u6c42\u7684\u5b9e\u73b0\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484273\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p>\u628a\u4e0a\u8ff0\u7684\u51e0\u4e2a\u6587\u4ef6\u521b\u5efa\u5b8c\u6210\u4e4b\u540e\u5c31\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u63d2\u4ef6\uff0c\u7136\u540e\u76f4\u63a5\u5b89\u88c5\u5230\u6d4f\u89c8\u5668\u6269\u5c55\u5373\u53ef\u3002<\/p>\n<\/p>\n<h2>\u4e94\u3001\u89e3\u91ca\u51e0\u4e2a\u6d88\u606f\u53d1\u9001\u548c\u63a5\u6536\u7684Api<\/h2>\n<h3>1. \u83b7\u53d6\u6307\u5b9a\u7684\u6d4f\u89c8\u5668\u6807\u7b7e\u9875\uff1a<\/h3>\n<pre><code>chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {})\n<\/code><\/pre>\n<h3>2. \u5411\u6307\u5b9a\u6807\u7b7e\u9875\u4e2d\u7684\u5185\u5bb9\u811a\u672c\u53d1\u9001\u4e00\u6761\u6d88\u606f\uff0c\u5176\u4e2d\u5305\u542b\u5728\u53d1\u9001\u56de\u54cd\u5e94\u65f6\u8fd0\u884c\u7684\u53ef\u9009\u56de\u8c03\u51fd\u6570\u3002\u5728\u5f53\u524d\u6269\u5c55\u7a0b\u5e8f\u7684\u6307\u5b9a\u6807\u7b7e\u9875\u4e2d\u8fd0\u884c\u7684\u6bcf\u4e2a\u5185\u5bb9\u811a\u672c\u4e2d\u90fd\u4f1a\u89e6\u53d1 <a href=\"https:\/\/link.segmentfault.com\/?enc=XjQSLKlpAwig9jpF6UJTVA%3D%3D.o5adJySxZ8m0%2BAFSdOh9BiXV8CTiXRU5XVZXhUHDo6IlpK%2BQUqM1kJhkMtP4ffpUActOGp%2Bs6zSKqXQPTwi5cdgQwIzo42%2F13j9muPIXiSjdkaV8qIQcBYKpfa9nr2%2BU\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">runtime.onMessage<\/a> \u4e8b\u4ef6\u3002<\/h3>\n<pre><code>chrome.tabs.sendMessage(tabs[0].id, { greeting: &quot;tag-remove&quot; }, function (response) { console.log(response); });\n<\/code><\/pre>\n<h3>3. \u5411\u6269\u5c55\u7a0b\u5e8f\u6216\u5176\u4ed6\u6269\u5c55\u7a0b\u5e8f\/\u5e94\u7528\u4e2d\u7684\u4e8b\u4ef6\u76d1\u542c\u5668\u53d1\u9001\u4e00\u6761\u6d88\u606f\u3002<a href=\"https:\/\/link.segmentfault.com\/?enc=%2BR5NPPtosFb62eHWGDA7Tw%3D%3D.8mmnyOUiepItDt6hDvZsP02PBjLDc77m%2BH2GeoDQ2sCI86sFrvv3rqoVcczMfPI02IaWCM6aj6Tw%2B8gQz5%2FL2URQuAjsOl5qqa7jer0MCNgc2osf9DaP%2BjMxcpoRdYUv\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u8bf7\u6ce8\u610f\uff0c\u6269\u5c55\u7a0b\u5e8f\u65e0\u6cd5\u4f7f\u7528\u6b64\u65b9\u6cd5\u5411\u5185\u5bb9\u811a\u672c\u53d1\u9001\u6d88\u606f\u3002\u5982\u9700\u5411\u5185\u5bb9\u811a\u672c\u53d1\u9001\u6d88\u606f\uff0c\u8bf7\u4f7f\u7528<\/a><\/h3>\n<pre><code>chrome.runtime.sendMessage(  extensionId?: string,  message: any,  options?: object,  callback?: function,)\n<\/code><\/pre>\n<h3>4. onMessage\uff0c\u901a\u8fc7\u6269\u5c55\u7a0b\u5e8f\u8fdb\u7a0b\uff08\u901a\u8fc7 <a href=\"https:\/\/link.segmentfault.com\/?enc=%2BCZnAJus6YoXx6YQVD282g%3D%3D.8SgDzxIDpN6byZaWgSOpj6d3szjs4LDsurN9cZnSTZYZNlZ1%2F6yCiJnkiXL%2B0Ea6j261DK4I0FCVdslAP0Zkflzchx8Aoed1eM6DWO3%2BmVkE0vysGqBlG%2Bkdemiu1AL%2F\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><code>runtime.sendMessage<\/code><\/a>\uff09\u6216\u5185\u5bb9\u811a\u672c\uff08\u901a\u8fc7 <a href=\"https:\/\/link.segmentfault.com\/?enc=zyYmJtBiNd8W5AJge0Npxw%3D%3D.%2BrdAKgAfz0HM7Hhm8CfjqkmuYkwnKWBYic9XxkpoEXQEDiIyQWJ6Aig2%2BW9E3BWyJxZhyexLVNzELY4mETrKr2ERB57iGb1A7OFDqcmzDWNhBHmF51jNGLDb6k%2FczmC1\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><code>tabs.sendMessage<\/code><\/a>\uff09\u53d1\u9001\u6d88\u606f\u65f6\u89e6\u53d1\u3002<\/h3>\n<pre><code>chrome.runtime.onMessage.addListener(  callback: function,)\n<\/code><\/pre>\n<h2>\u60f3\u4e86\u89e3\u5176\u4ed6\u6d4f\u89c8\u5668\u63d2\u4ef6Api\uff0c\u8bf7\u70b9\u51fb<a href=\"https:\/\/link.segmentfault.com\/?enc=W6Jm5QsD31QbJ3a4Iw1MHg%3D%3D.QBUbYCge6GrhGe9QL1UhUujZJw2v1RqAkTe0DpkP5sle0YlfdcuA57DR8jcdeSZXeAtPWzPtc%2FGaejflN8Tg3YmJNf6mvTGCsFZpl2hIUSs%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u8df3\u8f6c<\/a><\/h2>\n<h2>\u516d\u3001\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u4e30\u5bcc\u63d2\u4ef6\u7684\u80fd\u529b<\/h2>\n<h3>1. \u5b9e\u65f6\u5220\u9664\u9875\u9762\u4e0a\u7684\u5143\u7d20\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u70e6\u4eba\u7684\u5e7f\u544a\uff0c\u5220\u6389\u4ed6\u3002\u5e7f\u544a\u4e00\u822c\u90fd\u662f\u6709\u56fa\u5b9a\u7684\u5143\u7d20\u8282\u70b9\u7684\uff0c\u627e\u5230\u5143\u7d20\u8282\u70b9\u7684class\u6216\u8005id\uff0c\u6309\u4ee5\u4e0b\u5904\u7406\u3002<\/h3>\n<p>\u4ee5<a href=\"https:\/\/link.segmentfault.com\/?enc=k2GfbJ0PwZuWEUeTHHkX%2Fg%3D%3D.fxXR7MhTUHbVMBZ06cTbLjWPJWhsItCH8F%2BuaUhmBYw%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u767e\u5ea6\u4e00\u4e0b<\/a>\u9875\u9762\u4e3e\u4f8b\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5b9e\u65f6\u76d1\u542c\u7f51\u9875\u5143\u7d20\uff0c\u53d1\u73b0class\u4e3as-p-top\u7684\u5143\u7d20\u540e\u5c31\u4f1a\u5220\u9664\u6539\u5143\u7d20\uff0c\u8fd9\u91cc\u6211\u7ed9\u88ab\u5220\u9664\u5143\u7d20\u7684\u4f4d\u7f6e\u52a0\u4e86\u4e00\u4e2a\u7ea2\u8272\u8fb9\u6846\u7528\u6765\u6d4b\u8bd5\uff0c\u5b9e\u9645\u4f7f\u7528\u4e2d\u53ef\u4ee5\u5220\u9664\u6dfb\u52a0\u7ea2\u6846\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u5728content.js\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484274\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<\/p>\n<p><strong>\u901a\u8fc7\u4e0b\u9762\u4e24\u4e2a\u56fe\u5bf9\u6bd4\u53ef\u4ee5\u770b\u51fa\u4f7f\u7528\u63d2\u4ef6\u540e\u767e\u5ea6\u56fe\u7247\u88ab\u5220\u9664\u4e86\uff1a<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484275\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><br \/><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484276\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h3>2. \u6709\u4eba\u4e0d\u4e60\u60ef\u70b9\u5f00\u53f3\u4e0a\u89d2\u63d2\u4ef6\u518d\u70b9\u51fb\u529f\u80fd\u6309\u94ae\uff0c\u600e\u4e48\u529e\u5462\uff0c\u7b80\u5355\uff0c\u7ed9\u6d4f\u89c8\u5668\u53f3\u952e\u83dc\u5355\u6dfb\u52a0\u5feb\u6377\u952e\u3002<\/h3>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u4e3a\u6dfb\u52a0\u6d4f\u89c8\u5668\u53f3\u952e\u83dc\u5355\u7684\u5feb\u6377\u952e\uff0c\u5e76\u76d1\u542c\u83dc\u5355\u70b9\u51fb\u4e8b\u4ef6\uff0c\u53ef\u5728menu2\u4e2d\u53d1\u8d77\u8bf7\u6c42\u3002<\/p>\n<p>\u5728background.js\u4e2d\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484277\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p>\u6548\u679c\u5982\u4e0b\uff1a<br \/><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484278\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<h3>3. \u8fd8\u662f\u62e6\u622a\u5e7f\u544a\uff0c\u5e7f\u544a\u53ef\u80fd\u51fa\u73b0\u5728<strong>iframe\u4e2d<\/strong>\uff0c\u4f46\u662f\u5462\u6211\u4e0d\u60f3\u4f7f\u7528\u5220\u9664DOM\u7684\u65b9\u5f0f\uff0c\u600e\u4e48\u529e\u5462\uff0c\u90a3\u5c31\u76f4\u63a5\u62e6\u622a\u7f51\u7edc\u8bf7\u6c42\u3002<\/h3>\n<p>\u5728background.js\u4e2d\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484279\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<\/p>\n<p><strong>\u6211\u4eec\u8fd8\u4ee5baidu.com\u4e3a\u4f8b\uff0c\u5728<\/strong><a href=\"https:\/\/link.segmentfault.com\/?enc=Bfqpx%2B0XC4xATBZYjhFBDg%3D%3D.We5Mh7z4QhnDSEBIlzak2aYv8FKG51abCjrrHct2HzINW6Ur8icD21liN2m4LUM%2BWYHhHCN985nHFMxUP%2BijHqO%2BxRHGzvoDiNHdrCvNkUw%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><strong>MDN<\/strong><\/a><strong>\u4e2d\u6d4b\u8bd5\uff0c\u4fee\u6539iframe src\u7684\u503c\u4e3abaidu.com.<\/strong><\/p>\n<p><strong>\u4f7f\u7528\u63d2\u4ef6\u524d\u7ed3\u679c\u5982\u4e0b:<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484280\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p><strong>\u4f7f\u7528\u63d2\u4ef6\u540e\u7ed3\u679c\u5982\u4e0b\uff0c\u53ef\u4ee5\u53d1\u73b0iframe\u4e2d\u6ca1\u6709\u6e32\u67d3baidu.com\uff0c\u5e76\u4e14\u5728network\u4e2d\u53ef\u4ee5\u770b\u5230baidu.com\u88ab\u5c4f\u853d\u4e86:<\/strong><br \/><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484281\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<ol start=\"4\">\n<li>\u81ea\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5df1\u7684\u65b0\u5f00\u9875<\/li>\n<\/ol>\n<p>\u4e24\u6b65\u8d70<\/p>\n<p><strong>\u7b2c\u4e00\u6b65\uff1a\u5728manifest\u4e2d\u5b9a\u4e49newtab\uff08\u5c31\u662f\u4e00\u4e2ahtml\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u4f1a\u8986\u76d6\u539f\u751f\u7684\u6d4f\u89c8\u5668\u65b0\u5f00\u9875\uff09<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484282\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p><strong>\u7b2c\u4e8c\u6b65\uff1a\u521b\u5efanewtab.html\u6587\u4ef6\uff0c\u53ef\u4ee5\u5728\u8fd9\u4e2a\u6587\u4ef6\u5b9a\u4e49\u65b0\u5f00\u9875\u7684\u6837\u5f0f\u548cjs\uff0c\u4e14\u6b64\u6837\u5f0f\u6587\u4ef6\u548cjs\u6587\u4ef6\u4e0d\u7528\u6dfb\u52a0\u5230content\/_scripts\u4e2d<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484283\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p><strong>\u6548\u679c\u5982\u4e0b<\/strong><br \/><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484284\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<\/p>\n<h3><strong>5. \u6807\u8bb0\u9875\u9762\u6587\u672c<\/strong><\/h3>\n<p><strong>\u5728\u9605\u8bfb\u7f51\u9875\u6587\u6863\u65f6\uff0c\u7ecf\u5e38\u4f1a\u60f3\u6807\u8bb0\u4e00\u4e9b\u91cd\u70b9\u6587\u672c\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528\u6269\u5c55\u6765\u5b9e\u73b0\uff1a<\/strong><\/p>\n<p><strong>\u5728background.js\u4e2d\uff1a<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484285\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p><strong>\u5728content.js\u4e2d\uff1a<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484286\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p><strong>\u6548\u679c\uff1a<\/strong><\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484287\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p>\u529f\u80fd\u5148\u4e30\u5bcc\u5230\u8fd9\u91cc\uff0c\u540e\u9762\u518d\u7ee7\u7eed\u8865\u5145\/~<br \/><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000045484288\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" loading=\"lazy\"><\/p>\n<p>\u4e03\u3001\u53c2\u8003\u6587\u6863<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=Zg4C%2FlpgnkVuuDNKjAoDdg%3D%3D.ur8M9zTeaB2iT82LmPm3aohf4HDJlTm87PJnbsGY%2B7Ij%2B2jIqXa6AWO5vJQIsGmm3b1mAGcLPWIFN%2FM0Tj4REiS2KueQZ3X%2BYtIwGhIsEC4%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">chrome\u6269\u5c55\u53c2\u8003\u6587\u6863<\/a><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=fNDsXfs6gRMthgbodJAjpg%3D%3D.cKyhChD0BMX3gUHGT2VQhf0y%2Byf7bm9TY6fz6%2B5Nh0FSBiUBf0gJRuDewr5mQOtuzvmt9VALSXV%2F9s7Hv%2FphnsmyHvapvDxISdyuPGpJC7qWRDAH3WhD7uFwhN1NQ%2FRagKjsM%2FM8WCA2Qw1tVpGwZA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">chrome Api\u6587\u6863<\/a><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=PPHoaCeaQWCnOJtpxc5N%2Bw%3D%3D.B%2BBVNM03VltRovDCIJD%2BJ1ggowue%2FdzsoOY0ih2jYEUqH2zsadfwjnlvWidlT7DhSF6oBVO8evK6L5ZyzNXtIE9vNTT67pD2Sct1kuOmw9zfvo9lwmaQ%2FHU0ih%2FrDa5v\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">manifest\u6743\u9650\u914d\u7f6e\u6587\u6863<\/a><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000045484265\">https:\/\/segmentfault.com\/a\/1190000045484265<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u4eac\u4e1c\u5de5\u4e1a \u7126\u4e01 \u4e00\u3001\u4ec0\u4e48\u662f\u6d4f\u89c8\u5668\u63d2\u4ef6 \u6d4f\u89c8\u5668\u63d2\u4ef6\u662f\u4f9d\u9644\u4e8e\u6d4f\u89c8\u5668\uff0c\u7528\u6765\u62d3\u5c55\u7f51\u9875\u80fd\u529b\u7684\u7a0b\u5e8f\u3002\u63d2\u4ef6\u5177\u6709\u76d1\u542c\u6d4f\u89c8 [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020402","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020402"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020402\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}