使用 Chrome DevTools 调试 iOS 6+7 Mobile Safari
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11361822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debug iOS 6+7 Mobile Safari using the Chrome DevTools
提问by NVI
iOS 6 comes with built-in support for remote debugging (1 minute screencast). It plays nice with the new Safari Web Inspector which seems to be a 1 year old fork of WebKit Inspector. It misses some features such JS editing and WebSocket frames inspection.
iOS 6 内置了远程调试支持(1 分钟截屏)。它与新的 Safari Web Inspector 配合得很好,它似乎是 WebKit Inspector 的一个 1 年前的分支。它缺少一些功能,例如 JS 编辑和 WebSocket 帧检查。
Safari's Web inspector does use the WebKit remote debugging protocol. However, Safari does not use TCP/HTTP as a transport layer, thus making it incompatible with Chrome.
Safari 的 Web 检查器确实使用 WebKit 远程调试协议。但是,Safari 不使用 TCP/HTTP 作为传输层,因此与 Chrome 不兼容。
says Timothy Hatcher (aka Xenon), Apple employe
苹果员工 Timothy Hatcher(又名 Xenon)说
- What does Safari use for transport layer?
- Can I make a proxy from this mysterious transport layer to HTTP to make it work with Chrome DevTools?
- Safari 将什么用于传输层?
- 我可以从这个神秘的传输层到 HTTP 建立一个代理,使其与 Chrome DevTools 一起工作吗?
回答by NVI
The iOS WebKit Debug Proxyproject enables this.
在iOS版的WebKit调试代理项目支持这个。
To get started, install with homebrew:
首先,使用自制软件安装:
brew install ios-webkit-debug-proxy
Run the simulator (if running simulator):
运行模拟器(如果运行模拟器):
SIM_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
"$SIM_DIR/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator" \
-SimulateApplication \
$SIM_DIR/SDKs/iPhoneSimulator6.1.sdk/Applications/MobileSafari.app/MobileSafari
Run the proxy:
运行代理:
ios_webkit_debug_proxy
Check for errors
检查错误
Look on the device for an error message:
在设备上查看错误消息:
Could not connect to lockdownd. Exiting.: No such file or directory. Unable to attach inspector ios_webkit_debug_proxy
无法连接到lockedd。正在退出。:没有这样的文件或目录。无法附加检查器 ios_webkit_debug_proxy
Then check the device for a prompt like this(iOS 7 example: )
然后检查设备是否有这样的提示(iOS 7 示例:)
Trust the currently connected computer?
信任当前连接的计算机?
Choose "Trust" and try rerunning the proxy:
选择“信任”并尝试重新运行代理:
ios_webkit_debug_proxy
Open default devtools
打开默认开发工具
Then open http://localhost:9221
然后打开 http://localhost:9221
The DevTools are, by default, an older version (from Chrome 18 circa March 2012).
默认情况下,DevTools 是旧版本(来自 Chrome 18 大约 2012 年 3 月)。
Try modern devtools
尝试现代开发工具
Due to protocolchanges, parts the modern DevTools frontend may not work completely. You can try by opening
由于协议更改,部分现代 DevTools 前端可能无法完全工作。你可以打开试试
chrome-devtools://devtools/bundled/inspector.html?ws=localhost:9222/devtools/pag??e/2
where the port
and page
values are the values you're seeing from http://localhost:9221
. Again, this may indeed be buggy.
其中port
和page
值是您从 中看到的值http://localhost:9221
。同样,这可能确实有问题。
Read more docs at the ios-webkit-debug-proxy project page.
在ios-webkit-debug-proxy 项目页面阅读更多文档。
Update:This works with iOS7 as well. Update: Added fresh devtools frontend instructions via patrick.. Update: Changed devtools.html to inspector.html for Chrome 45, and the new ws
hack via Scheintod.
更新:这也适用于iOS7。更新:加入新鲜devtools前端通过指令帕特里克..更新:改变devtools.html到inspector.html为Chrome 45,而新ws
通过Scheintod黑客。
回答by also
According to https://github.com/andydavies/node-iosdriver,
根据https://github.com/andydavies/node-iosdriver,
Safari uses the same debugging commands as Chrome but wrapped as binary plists over RPC rather than JSON over websockets.
Safari 使用与 Chrome 相同的调试命令,但通过 RPC 包装为二进制 plist,而不是通过 websockets 的 JSON。
So, yes, it would possible to write a proxy.
所以,是的,可以编写代理。
I found this threadby looking at what TCP connections Safari was making while connected to the MobileSafari inspector, seeing that it was connected to a process called webinspectord
and Googling that:
我通过查看 Safari 在连接到 MobileSafari 检查器时所做的 TCP 连接发现了这个线程,看到它连接到一个名为的进程webinspectord
并在谷歌上搜索:
# pgrep -lf /Applications/Safari.app
33170 /Applications/Safari.app/Contents/MacOS/Safari -psn_0_21144617
# lsof -p 33170 | grep TCP
Safari 33170 ryan 16u IPv6 0x799d5f43b472a241 0t0 TCP localhost:54892->localhost:27753 (ESTABLISHED)
# lsof -i :27753
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
launchd 371 ryan 42u IPv6 0x799d5f43b472aa01 0t0 TCP localhost:27753 (LISTEN)
Safari 33170 ryan 16u IPv6 0x799d5f43b472a241 0t0 TCP localhost:54892->localhost:27753 (ESTABLISHED)
webinspec 33182 ryan 6u IPv6 0x799d5f43b472aa01 0t0 TCP localhost:27753 (LISTEN)
webinspec 33182 ryan 7u IPv6 0x799d5f43b181a621 0t0 TCP localhost:27753->localhost:54892 (ESTABLISHED)
# ps p 33182
PID TT STAT TIME COMMAND
33182 ?? S 0:00.28 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/usr/libexec/webinspectord