简体   繁体   English

如何在 Chrome 开发者工具中禁用 JavaScript?

[英]How to disable JavaScript in Chrome Developer Tools?

I am trying to debug the features of a website when users disable their JavaScript.当用户禁用他们的 JavaScript 时,我试图调试网站的功能。 I was wondering how do you disable JavaScript for a page from the Google Chrome DevTools?我想知道如何从 Google Chrome DevTools 禁用页面的 JavaScript?

在此处输入图片说明

Click the gear icon in the corner of the Developer Tools, click Settings, then check Disable Javascript under Debugger .点击开发者工具一角的齿轮图标,点击设置,然后在Debugger下勾选Disable Javascript

Update August 2020 2020 年 8 月更新

  1. Developer Tools (F12)开发者工具 (F12)
  2. Click the Gear icon单击齿轮图标

设置

  1. Should open the Preference tab应该打开首选项选项卡
  2. Disable Javascript option is on the far right禁用 Javascript 选项位于最右侧

禁用 JS 选项

Original answer原答案

  1. Developer Tools (F12)开发者工具 (F12)
  2. Three vertical dots in upper right右上角的三个垂直点
  3. Settings设置
  4. Under the "Preferences" tab on the left在左侧的“首选项”选项卡下

首选项部分

  1. There will be a "Debugger" section with the option (probably on far right)将有一个带有选项的“调试器”部分(可能在最右边)

禁用复选框

Official documentation: Disable JavaScript With Chrome DevTools官方文档: 使用 Chrome DevTools 禁用 JavaScript

There's now a command menu built into DevTools that makes it easier to disable JavaScript.现在 DevTools 中内置了一个命令菜单,可以更轻松地禁用 JavaScript。 This has been around as of April 2016 or so.这大约是在 2016 年 4 月左右。

  1. Open DevTools . 打开开发者工具
  2. Press Command + Shift + P (Mac) or Control + Shift + P (Windows, Linux) to open the Command Menu.Command + Shift + P (Mac) 或Control + Shift + P (Windows、Linux)打开命令菜单。 Make sure that your cursor's focus is on the DevTools window, not your browser viewport.确保光标的焦点在 DevTools 窗口上,而不是浏览器视口上。
  3. Type Disable JavaScript (or some version of that... it's a fuzzy search) and then press Enter .键入Disable JavaScript (或某个版本的...这是一个模糊搜索),然后按Enter

Use the Enable JavaScript command when you want to turn it back on.当您想重新打开它时,请使用Enable JavaScript命令。

通过命令菜单禁用js

chrome://settings/content Javascript/管理异常

This extension makes it faster (I am the author) : Quick Javascript Switcher这个扩展使它更快(我是作者): Quick Javascript Switcher

It is open source: https://github.com/maximelebreton/quick-javascript-switcher它是开源的: https : //github.com/maximelebreton/quick-javascript-switcher

You can also run Chrome with JavaScript disabled by default by using the flag:您还可以使用以下标志在默认情况下禁用 JavaScript 的情况下运行 Chrome:

-disable-javascript

You would use this for example by running Chrome like this:例如,您可以通过像这样运行 Chrome 来使用它:

C:\Documents and Settings\%username%\Local Settings\Application Data\Google\Chrome" -disable-javascript

The quickest way is problably this one:最快的方法可能是这个:

  • F12 to open the dev console F12 打开开发控制台
  • ctrl + shift + p to open the command tool (windows) ctrl + shift + p 打开命令工具(windows)
  • Type 'disable javascript' and hit enter输入“禁用 javascript”并按回车键

On OSX, I had to click the triple vertical dots, and uncheck a box in the settings section.在 OSX 上,我必须单击三个垂直点,然后取消选中设置部分中的一个框。 Which can also be opened with f1也可以用f1打开

Using only the keyboard at least for Windows 10:至少在 Windows 10 中仅使用键盘:

  • F12 , shows Developer Tools F12 , 显示开发者工具
  • F1 , shows Settings F1 , 显示设置
  • tab , moves to the "Disable Javascript" check box tab ,移至“禁用 Javascript”复选框
  • space , toggles the option空格, 切换选项
  • esc , hides Settings esc , 隐藏设置

To temporarily block JavaScript on a domain :要临时阻止域上的 JavaScript:

  1. Click on the Button left to the address on the address bar (which says View site information )单击地址栏上地址左侧的按钮( View site information
  2. In the drop-down next to JavaScript , select Always block on this siteJavaScript旁边的下拉列表中,选择Always block on this site
  3. Reload Page重新加载页面

On Mac OS X:在 Mac OS X 上:

  • Preferences喜好
  • Show advanced settings显示高级设置
  • Press the "content settings" button按“内容设置”按钮
  • Scroll to the "JavaScript" section滚动到“JavaScript”部分
  • Check the checkbox in front of "Do not allow any site to run JavaScript"选中“不允许任何站点运行 JavaScript”前面的复选框

The Chrome Quick JavaScript Switcher extension is a lot easier though :-)不过, Chrome Quick JavaScript Switcher 扩展要容易得多:-)

  • Go to options (Windows: three vertical dots in the top right) -> Settings, or hit F1.转到选项(Windows:右上角的三个垂直点)-> 设置,或按 F1。
  • In the General section you find "disable JavaScript"在“常规”部分,您会找到“禁用 JavaScript”

The gear icon is no longer part of developer tools.齿轮图标不再是开发人员工具的一部分。 Since Chome 30.0 it is not even possible to bring it back ( In Google Chrome Developer Tools, the toolbar icons disappeared. What gives? )由于 Chome 30.0 甚至无法将其恢复( 在 Google Chrome 开发者工具中,工具栏图标消失了。是什么给的?

The fast way :快速方法

1) just click on CTRL + SHIFT + P 1) 只需点击CTRL + SHIFT + P

2) fill the field by the 3 letters dis and will appear this box and select the item Disable Javascript 2) 用 3 个字母dis填写该字段,将出现此框并选择项Disable Javascript

禁用 JavaScript . .

that's all folks!这就是所有人!

  • Click the ⋮ menu in the corner of the Developer Tools, click Settings点击开发者工具一角的⋮菜单,点击设置
  • Click on Advanced at the bottom点击底部的高级
  • Click on Content Settings点击内容设置
  • Click on JavaScript单击 JavaScript
  • Switch off关掉

Full and fast instructions for Chrome browsers (Opera incl.) Chrome 浏览器(包括 Opera)的完整快速说明

The first way第一种方式

  1. If Developer Tools aren't open then press F12 key on keyboard to show the Developer Tools.如果开发人员工具未打开,则按键盘上的F12键以显示开发人员工具。 In Opera browser you have to use key combination Ctrl + Shift + i on keyboard to open it.在 Opera 浏览器中,您必须使用键盘上的组合键Ctrl + Shift + i才能打开它。
  2. To show the settings just press F1 key on keyboard.要显示设置,只需按键盘上的F1键。 The Developer Tools window must be focused when you are doing it.执行此操作时,必须聚焦“开发人员工具”窗口。 Or if you want to open the settings with the mouse then you have to click on button in the top right corner of the Developer Tools, then click Settings in the menu.或者,如果您想用鼠标打开设置,则必须单击开发人员工具右上角的按钮,然后单击菜单中的Settings

Then you have to scroll down the settings window to bottom and then you will see the checkbox for disabling JavaScript like follows:然后您必须将设置窗口向下滚动到底部,然后您将看到禁用 JavaScript 的复选框,如下所示:

在 Chrome 开发者工具中禁用 JavaScript

Just click on this checkbox and push esc key on keyboard for hide the settings.只需单击此复选框并按键盘上的esc键即可隐藏设置。 If you want to enable it then you have to do the same way again.如果要启用它,则必须再次执行相同的操作。

The second way第二种方式

  1. If Developer Tools aren't open then open it like in the first way is described.如果开发人员工具未打开,则像描述的第一种方式一样打开它。
  2. Press the key combination Ctrl + Shift + P (for Windows or Linux) or Cmd (⌘) + Shift + P (for Mac) to open the Command Menu.按组合键Ctrl + Shift + P (对于 Windows 或 Linux)或Cmd (⌘) + Shift + P (对于 Mac)以打开命令菜单。 Be sure that the focus is on the DevTools window.确保焦点在 DevTools 窗口上。
  3. Type there "Disable JavaScript" and then press Enter or click it with the mouse.在那里输入“禁用 JavaScript”,然后按Enter 键或用鼠标单击它。 If you want to turn back the enanled JS then open the Command Menu again and type there "Enable JavaScript" and then press Enter or click it with the mouse.如果您想返回已启用的 JS,请再次打开命令菜单并在其中键入“启用 JavaScript”,然后按Enter或用鼠标单击它。 You could also write just only "JavaScript" or "Java" there and then choose it with the mouse.您也可以在那里只写“JavaScript”或“Java”,然后用鼠标选择它。

在 Chrome 开发者工具中禁用 JavaScript

If all this does not work如果这一切都不起作用

For some reason it is possible that it does not work.由于某种原因,它可能不起作用。 I this case open a new empty site in "Incognito Mode" and do all this there.我在这种情况下以“隐身模式”打开一个新的空站点,然后在那里执行所有操作。

The quickest way最快的方式

In Chrome Web Store or on Opera Addon site you can find and install extensions which do it per one click.在 Chrome 网上应用店或 Opera Addon 站点上,您可以找到并安装扩展程序,这些扩展程序一键即可完成。 Just search "Javascript Switcher" :只需搜索"Javascript Switcher"

Press F8 for temporarily freezing / unfreezing JS (with DevTools open).F8临时冻结/解冻 JS(打开 DevTools)。

This is very useful for debugging UI issues on elements that may lose focus if you click or press anything outside of that element.这对于调试元素上的 UI 问题非常有用,如果您单击或按下该元素之外的任何内容,这些元素可能会失去焦点。 (Chrome 71.0.3578.98, Ubuntu 18.10) (Chrome 71.0.3578.98,Ubuntu 18.10)

Paste it: chrome://settings/content粘贴它:chrome://settings/content

Go to "Javascript" section and disable it.转到“Javascript”部分并禁用它。

Chrome://chrome/settings/Privacy/Content settings/JavaScript

在那里您可以在Manage exceptions..粘贴您网站的 URL Manage exceptions..并将 JavaScript 优先级从允许更改为阻止。

这是 windows 的最新设置

Settings > Advanced > Privacy and security > Site Settings > Javascript > Blocked then get switch on and off

good question, i try so many way, but it is curry and boring, until i find shortcut.好问题,我尝试了很多方法,但它是咖喱和无聊,直到我找到捷径。

  1. alt + cmd + i, this open dev tools, unless you use pocket, that need set other shortcut. alt + cmd + i,这个打开的开发工具,除非你使用pocket,否则需要设置其他快捷方式。
  2. shift + cmd + p, then input: javascript shift + cmd + p,然后输入:javascript

only two shortcut, but i think safari is more convenient for that.只有两个捷径,但我认为 safari 更方便。

There's a settings in chrome chrome 中有一个设置

open the menu from chrome, click settings > type in "javascript" in the search bar > click site settings > click javascript.从 chrome 打开菜单,单击设置 > 在搜索栏中输入“javascript”> 单击站点设置 > 单击 javascript。

from here you can toggle javascript specifically to a site using their url.从这里您可以使用 url 将 javascript 专门切换到站点。 or just click the big button to allow/block it to all sites.或者只需单击大按钮以允许/阻止它访问所有站点。

在此处输入图片说明

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

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