简体   繁体   English

在Chrome DevTools中如何防止脚本执行

[英]In Chrome DevTools How to prevent script from executing

I have a page not on my server, where a particular is running during page-loading 我的服务器上没有页面,页面加载期间正在运行该页面

...other stuff...
<script src="http://someserver.com/script.js"></script>
...other stuff...

and causing some problems. 并引起一些问题。
I need to debug this so first I'd like to prevent that script from loading. 我需要调试它,所以首先我想阻止该脚本加载。

How can I do this? 我怎样才能做到这一点? All I've found is that I can delete, edit or add a script after the page has loaded. 我发现的是,页面加载可以删除,编辑或添加脚本。 But that is not what I need. 但这不是我所需要的。 I need to load the whole page but skip loading this very script. 我需要加载整个页面,但跳过加载此脚本。

Google Chrome can now do this for you. Google Chrome现在可以为您执行此操作。

  1. Open developer tools 开放的开发人员工具
  2. Open the network tab 打开网络标签
  3. Navigate to the site 导航到该站点
  4. Find the request that loads the script 查找加载脚本的请求
  5. Right-click on the request and select "Block request URL" 右键单击请求,然后选择“阻止请求URL”

Chrome will now block the request that loads that script. Chrome现在将阻止加载该脚本的请求。 To remove the block: 删除块:

  1. Open the console at the bottom of developer tools, fyi the "Esc" (escape) key will toggle it. 打开开发人员工具底部的控制台,按“ Esc”(转义)键将其切换。
  2. Open the "Request Blocking" tab (you'll find it in the 3 dot menu next to the "Console" tab if you don't have the tab available) 打开“请求阻止”标签(如果您没有可用的标签,请在“控制台”标签旁边的3点菜单中找到它)
  3. Click the stop looking icon with the title of "Remove all patterns" 单击标题为“删除所有样式”的停止搜索图标

There are a couple of approaches to this... the first being the old school way of handling ad blocking (which this is similar to), which is simply create a dns entry in your hosts file (C:\\windows\\system32\\drivers\\etc\\hosts on windows) and alias someserver.com to localhost 127.0.0.1: 有两种方法...第一种是处理广告拦截的老式方法(类似于),它只是在主机文件(C:\\ windows \\ system32 \\ drivers)中创建dns条目。 Windows上的\\ etc \\ hosts),并将someserver.com别名为localhost 127.0.0.1:

someserver.com  127.0.0.1

This, however, has the unfortunate side-effect of not loading ANYTHING from someserver.com. 但是,这有一个不幸的副作用,就是没有从someserver.com加载任何东西。

Another option is to use something like adblock plus, and just add the script to the "Add your own filters" tab, where the syntax for your filter will be: 另一种选择是使用诸如adblock plus之类的东西,只需将脚本添加到“添加您自己的过滤器”标签中,其中过滤器的语法为:

http://someserver.com/script.js

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM