{"id":3197,"date":"2024-11-10T11:14:44","date_gmt":"2024-11-10T03:14:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3197\/"},"modified":"2024-11-10T11:14:44","modified_gmt":"2024-11-10T03:14:44","slug":"%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8bjs%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3197\/","title":{"rendered":"\u5982\u4f55\u67e5\u770bjs\u9519\u8bef"},"content":{"rendered":"<blockquote><p>\n  \u8981\u67e5\u770b javascript \u9519\u8bef\uff0c\u6709\u4ee5\u4e0b\u4e09\u79cd\u65b9\u6cd5\uff1a\u6d4f\u89c8\u5668\u63a7\u5236\u53f0\uff1a\u6253\u5f00\u5f00\u53d1\u8005\u5de5\u5177\u5e76\u5207\u6362\u5230\u63a7\u5236\u53f0\u9009\u9879\u5361\u3002\u65e5\u5fd7\u6587\u4ef6\uff1a\u6253\u5f00\u5f00\u53d1\u8005\u5de5\u5177\u3001\u5207\u6362\u5230\u6e90\u9009\u9879\u5361\uff0c\u7136\u540e\u5355\u51fb\u9519\u8bef\u3002\u4e8b\u4ef6\u4fa6\u542c\u5668\uff1a\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e8b\u4ef6\u4fa6\u542c\u5668\u4ee5\u4fa6\u542c error \u4e8b\u4ef6\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110806512429316.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u67e5\u770bjs\u9519\u8bef\u63d2\u56fe\" alt=\"\u5982\u4f55\u67e5\u770bjs\u9519\u8bef\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b JS \u9519\u8bef<\/strong><\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u6d4f\u89c8\u5668\u63a7\u5236\u53f0<\/strong><\/p>\n<ol>\n<li>\u6253\u5f00\u6d4f\u89c8\u5668\uff08\u5982 Chrome\u3001Firefox \u6216 Safari\uff09\u3002<\/li>\n<li>\u5728\u9875\u9762\u4e0a\u6309 <strong>F12<\/strong>\uff08\u6216 <strong>Ctrl+Shift+I<\/strong>\uff09\u6253\u5f00\u5f00\u53d1\u8005\u5de5\u5177\u3002<\/li>\n<li>\u5207\u6362\u5230 <strong>\u63a7\u5236\u53f0<\/strong>\u9009\u9879\u5361\u3002<\/li>\n<\/ol>\n<p><strong>\u65b9\u6cd5 2\uff1a\u65e5\u5fd7\u6587\u4ef6<\/strong><\/p>\n<ol>\n<li>\u6253\u5f00\u6d4f\u89c8\u5668\u5f00\u53d1\u8005\u5de5\u5177\uff08\u5982\u65b9\u6cd5 1 \u6240\u8ff0\uff09\u3002<\/li>\n<li>\u5207\u6362\u5230 <strong>\u6e90<\/strong>\u9009\u9879\u5361\u3002<\/li>\n<li>\u5728\u5de6\u4fa7\u9762\u677f\u4e2d\u5355\u51fb <strong>\u9519\u8bef<\/strong>\u3002<\/li>\n<\/ol>\n<p><strong>\u65b9\u6cd5 3\uff1a\u4e8b\u4ef6\u4fa6\u542c\u5668<\/strong><\/p>\n<ol>\n<li>\n<p>\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e8b\u4ef6\u4fa6\u542c\u5668\u4ee5\u4fa6\u542c <strong>error<\/strong> \u4e8b\u4ef6\uff1a<\/p>\n<pre>window.addEventListener('error', (event) =&gt; {\n  \/\/ \u5904\u7406\u9519\u8bef\u4e8b\u4ef6\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<\/ol>\n<p><strong>\u8be6\u7ec6\u89e3\u91ca<\/strong><\/p>\n<p><strong>\u6d4f\u89c8\u5668\u63a7\u5236\u53f0<\/strong><\/p>\n<ul>\n<li>\u63a7\u5236\u53f0\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u7528\u4e8e\u5b9e\u65f6\u67e5\u770b\u9519\u8bef\u548c\u8b66\u544a\u3002<\/li>\n<li>\u5b83\u53ef\u4ee5\u663e\u793a\u9519\u8bef\u6d88\u606f\u3001\u5806\u6808\u8ddf\u8e2a\u548c\u6e90\u6587\u4ef6\u4fe1\u606f\u3002<\/li>\n<li>\u4f7f\u7528\u63a7\u5236\u53f0\u7684\u4f18\u70b9\u662f\uff0c\u5b83\u53ef\u4ee5\u7acb\u5373\u67e5\u770b\u9519\u8bef\uff0c\u800c\u65e0\u9700\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>\u65e5\u5fd7\u6587\u4ef6<\/strong><\/p>\n<ul>\n<li>\u65e5\u5fd7\u6587\u4ef6\u5305\u542b\u6309\u65f6\u95f4\u987a\u5e8f\u8bb0\u5f55\u7684\u9519\u8bef\u548c\u8b66\u544a\u4fe1\u606f\u3002<\/li>\n<li>\u67d0\u4e9b\u6d4f\u89c8\u5668\uff08\u5982 Chrome\uff09\u5c06\u5176\u9519\u8bef\u65e5\u5fd7\u5b58\u50a8\u5728 <strong>localStorage<\/strong> \u4e2d\u3002<\/li>\n<li>\u8981\u67e5\u770b\u65e5\u5fd7\u6587\u4ef6\uff0c\u9700\u8981\u6253\u5f00\u5f00\u53d1\u8005\u5de5\u5177\u5e76\u5207\u6362\u5230 <strong>\u6e90<\/strong>\u9009\u9879\u5361\u3002<\/li>\n<\/ul>\n<p><strong>\u4e8b\u4ef6\u4fa6\u542c\u5668<\/strong><\/p>\n<ul>\n<li>\u4e8b\u4ef6\u4fa6\u542c\u5668\u5141\u8bb8\u60a8\u5728\u53d1\u751f <strong>error<\/strong> \u4e8b\u4ef6\u65f6\u5904\u7406\u81ea\u5b9a\u4e49\u4ee3\u7801\u3002<\/li>\n<li>\u8fd9\u53ef\u4ee5\u8ba9\u60a8\u4ee5\u7279\u5b9a\u65b9\u5f0f\u5904\u7406\u9519\u8bef\uff0c\u4f8b\u5982\u8bb0\u5f55\u9519\u8bef\u6216\u663e\u793a\u53cb\u597d\u7684\u9519\u8bef\u6d88\u606f\u7ed9\u7528\u6237\u3002<\/li>\n<li>\u4e8b\u4ef6\u4fa6\u542c\u5668\u6700\u9002\u5408\u9700\u8981\u81ea\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u7684\u590d\u6742\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u67e5\u770bjs\u9519\u8bef\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u67e5\u770b javascript \u9519\u8bef\uff0c\u6709\u4ee5\u4e0b\u4e09\u79cd\u65b9\u6cd5\uff1a\u6d4f\u89c8\u5668\u63a7\u5236\u53f0\uff1a\u6253\u5f00\u5f00\u53d1\u8005\u5de5\u5177\u5e76\u5207\u6362\u5230\u63a7\u5236\u53f0\u9009\u9879\u5361\u3002\u65e5\u5fd7\u6587\u4ef6\uff1a\u6253\u5f00\u5f00\u53d1\u8005\u5de5\u5177\u3001\u5207\u6362\u5230\u6e90\u9009\u9879\u5361\uff0c\u7136\u540e\u5355\u51fb\u9519\u8bef\u3002\u4e8b\u4ef6\u4fa6\u542c\u5668\uff1a\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e8b\u4ef6\u4fa6\u542c\u5668\u4ee5\u4fa6\u542c error \u4e8b\u4ef6\u3002 \u5982\u4f55\u67e5\u770b JS \u9519\u8bef \u65b9\u6cd5 1\uff1a\u6d4f\u89c8\u5668\u63a7\u5236\u53f0 \u6253\u5f00\u6d4f\u89c8\u5668\uff08\u5982 Chrome\u3001Firefox \u6216 Safari\uff09\u3002 \u5728\u9875\u9762\u4e0a\u6309 F12\uff08\u6216 Ctrl+Shift+I\uff09\u6253\u5f00\u5f00\u53d1\u8005\u5de5\u5177\u3002 \u5207\u6362\u5230 \u63a7\u5236\u53f0\u9009\u9879\u5361\u3002 \u65b9\u6cd5 2\uff1a\u65e5\u5fd7\u6587\u4ef6 \u6253\u5f00\u6d4f\u89c8\u5668\u5f00\u53d1\u8005\u5de5\u5177\uff08\u5982\u65b9\u6cd5 1 \u6240\u8ff0\uff09\u3002 \u5207\u6362\u5230 \u6e90\u9009\u9879\u5361\u3002 \u5728\u5de6\u4fa7\u9762\u677f\u4e2d\u5355\u51fb \u9519\u8bef\u3002 \u65b9\u6cd5 3\uff1a\u4e8b\u4ef6\u4fa6\u542c\u5668 \u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e8b\u4ef6\u4fa6\u542c\u5668\u4ee5\u4fa6\u542c error \u4e8b\u4ef6\uff1a window.addEventListener(&#8216;error&#8217;, (event) =&gt; { \/\/ \u5904\u7406\u9519\u8bef\u4e8b\u4ef6 }); \u767b\u5f55\u540e\u590d\u5236 \u8be6\u7ec6\u89e3\u91ca \u6d4f\u89c8\u5668\u63a7\u5236\u53f0 \u63a7\u5236\u53f0\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u7528\u4e8e\u5b9e\u65f6\u67e5\u770b\u9519\u8bef\u548c\u8b66\u544a\u3002 \u5b83\u53ef\u4ee5\u663e\u793a\u9519\u8bef\u6d88\u606f\u3001\u5806\u6808\u8ddf\u8e2a\u548c\u6e90\u6587\u4ef6\u4fe1\u606f\u3002 \u4f7f\u7528\u63a7\u5236\u53f0\u7684\u4f18\u70b9\u662f\uff0c\u5b83\u53ef\u4ee5\u7acb\u5373\u67e5\u770b\u9519\u8bef\uff0c\u800c\u65e0\u9700\u68c0\u67e5\u65e5\u5fd7\u6587\u4ef6\u3002 \u65e5\u5fd7\u6587\u4ef6 \u65e5\u5fd7\u6587\u4ef6\u5305\u542b\u6309\u65f6\u95f4\u987a\u5e8f\u8bb0\u5f55\u7684\u9519\u8bef\u548c\u8b66\u544a\u4fe1\u606f\u3002 \u67d0\u4e9b\u6d4f\u89c8\u5668\uff08\u5982 Chrome\uff09\u5c06\u5176\u9519\u8bef\u65e5\u5fd7\u5b58\u50a8\u5728 localStorage \u4e2d\u3002 \u8981\u67e5\u770b\u65e5\u5fd7\u6587\u4ef6\uff0c\u9700\u8981\u6253\u5f00\u5f00\u53d1\u8005\u5de5\u5177\u5e76\u5207\u6362\u5230 \u6e90\u9009\u9879\u5361\u3002 \u4e8b\u4ef6\u4fa6\u542c\u5668 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3197","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3197"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3197\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}