Chrome可以在打开包含“debugger”关键字的页面时自动打开调试器吗?
以前有一个命令行标志 --always-enable-devtools,现在似乎没有了。但是,您可以使用一个巧妙的技巧,尽管如果您不在OSX上,就必须稍微调整一下才能重现我正在做的事情。
我创建了两个shell脚本,'developer-chrome'和'debugger-chrome'。
'developer-chrome'是我希望始终观察的实例,而'debugger-chrome'将坐在我的第二个显示器上,这样我就可以看到控制台消息并在需要时触发'developer-chrome'。
#!/bin/bash
export PROFILE=$HOME/develop-chromium-profile
export DISK_CACHEDIR=/tmp/develop-chromium-profile-cache
export DISK_CACHESIZE=0
export MEDIA_CACHESIZE=0
/Applications/Chromium.app/Contents/MacOS/Chromium \
--remote-debugging-port=4096 \
--user-data-dir=${PROFILE} \
--enable-experimental-webgl=yes \
--window-position=3000,400 \
--window-size=1200,1000 \
--no-pings \
--disk-cache-dir=${DISK_CACHEDIR} \
--disk-cache-size=${DISK_CACHESIZE} \
--media-cache-size=${MEDIA_CACHESIZE} \
--disable-geolocation \
--ash-immersive \
--disable-application-cache \
--pinned-tab-count=1 http://some_url_im_developing_on/
#!/bin/bash
export PROFILE=$HOME/debugger-chromium-profile
export DISK_CACHEDIR=/tmp/debugger-chromium-profile-cache
export DISK_CACHESIZE=0
export MEDIA_CACHESIZE=0
/Applications/Chromium.app/Contents/MacOS/Chromium \
--user-data-dir=${PROFILE} \
--enable-experimental-webgl=yes \
--window-position=2400,400 \
--window-size=1200,1000 \
--no-pings \
--disk-cache-dir=${DISK_CACHEDIR} \
--disk-cache-size=${DISK_CACHESIZE} \
--media-cache-size=${MEDIA_CACHESIZE} \
--disable-geolocation \
--ash-immersive \
--disable-application-cache \
--pinned-tab-count=1 http://localhost:4096/
可以的。
谷歌浏览器可以打开调试器,只需要使用标志 debbuger。以下是示例:
<script>
(yourcode here)
debugger;
(next code to debug)
</script>
开发者工具的源代码面板将自动为您打开到该特定行。
它也适用于Internet Explorer 11。
在43.x版本上进行了测试。
当我在 Chrome(Mac 上)中使用以下代码 debugger;
时,它不会自动打开控制台,只有在开发者工具已处于活动状态时才会运行。 在 Firefox 中执行相同的操作并运行我的页面/脚本(安装了 Firebug)时,当命中 debugger;
语句时 JavaScript 控制台/调试器就会打开。
以上是我的经验。