简体   繁体   English

如何以编程方式在chrome developer工具中禁用javascript?

[英]How to disable javascript in chrome developer tools programmatically?

The other related question only states how to switch on/off JavaScript via the GUI Chrome provides. 另一个相关问题仅说明如何通过Chrome提供的GUI打开/关闭JavaScript。 However, I want to toggle JavaScript programmatically from chrome console OR with a single key stroke (Such as tapping F12). 但是,我想以编程方式从Chrome控制台或单键击中切换JavaScript(例如点击F12)。

The reason I want this ability is because I am working on a web application which has a dropdown menu that I want to modify; 我想要这种能力的原因是因为我正在开发一个Web应用程序,它有一个我想要修改的下拉菜单; I am not sure where in the codebase this dropdown menu is so I would like to pause execution and inspect it. 我不确定代码库中的这个下拉菜单是什么,所以我想暂停执行并检查它。 Whenever I click on any of my developer tool options though to pause execution, it closes the dropdown menu. 每当我点击我的任何开发人员工具选项但暂停执行时,它会关闭下拉菜单。

A potential solution would be to simply put a debugger in the code where the dropdown menu is, but this is a chicken-and-egg problem because the whole point of pausing execution is to locate where in the codebase this drop down menu is. 一个潜在的解决方案是简单地将调试器放在下拉菜单所在的代码中,但这是一个鸡与蛋的问题,因为暂停执行的整个要点是找到代码库中这个下拉菜单的位置。

You can write a simple Chrome extension to do what you want. 您可以编写一个简单的Chrome扩展程序来执行您想要的操作。 Chrome provides a JavaScript API were you can allow or block JavaScript using contentSettings and the property you will need to set or unset is JavascriptContentSetting. Chrome提供了JavaScript API,您可以使用contentSettings允许或阻止JavaScript,您需要设置或取消设置的属性是JavascriptContentSetting。

https://developer.chrome.com/extensions/contentSettings https://developer.chrome.com/extensions/contentSettings

https://developer.chrome.com/extensions/contentSettings#type-JavascriptContentSetting https://developer.chrome.com/extensions/contentSettings#type-JavascriptContentSetting

To add the keyboard shortcut, you add it to the manifest as described here: 要添加键盘快捷键,请按照此处所述将其添加到清单:

https://developer.chrome.com/extensions/commands https://developer.chrome.com/extensions/commands

Just in case you have not built an extension before (don't worry, it is pretty easy), here is a walk-though on putting together your first: 万一你以前没有建立一个扩展(不要担心,这很容易),这里是一个步骤 - 虽然把你的第一个:

https://developer.chrome.com/extensions/getstarted https://developer.chrome.com/extensions/getstarted

Hope this helps. 希望这可以帮助。

In developer tools, you can right-click the node in the inspector tab and use the 'Force element state' sub-menu to simulate a mouse hover. 在开发人员工具中,可以右键单击“检查器”选项卡中的节点,然后使用“强制元素状态”子菜单模拟鼠标悬停。

Also you should get a lot of event listeners in the form of file:line that you can work backwards from to locate the relevant code. 此外,你应该以file:line的形式获得许多事件监听器,你可以向后工作以找到相关的代码。

Also++, you can simulate events in JS How to simulate a mouse click using JavaScript? 另外++,您可以在JS中模拟事件如何使用JavaScript模拟鼠标点击?

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

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