1.安装ios_webkit_debug_proxy
Mac 可以简单的使用 brew 安装:
brew install ios-webkit-debug-proxy
Linux 或者 Mac:
sudo apt-get install \
autoconf automake \
libusb-dev libusb-1.0-0-dev \
libplist-dev libplist++-dev \
usbmuxd \
libimobiledevice-dev
./autogen.sh
make
sudo make install
2.开启ios_webkit_debug_proxy
ios_webkit_debug_proxy -c uuid:port -d
uuid:ios设备号可通过 idevice_id -l 查询
port:端口
3.获取websocket地址
get http://localhost:port/json *port为之前开启ios_webkit_debug_proxy的端口号
返回内容为:[{
"devtoolsFrontendUrl": "/devtools/devtools.html?ws=localhost:27753/devtools/page/7",
"faviconUrl": "",
"thumbnailUrl": "/thumb/https://www.baidu.com",
"title": "百度一下",
"url": "https://www.baidu.com",
"webSocketDebuggerUrl": "ws://localhost:27753/devtools/page/7",
"appId": "PID:1231"
}]
webSocketDebuggerUrl就是websocket地址
4.建立websocket连接,并发送请求通信
发送请求格式:
{"method":"Runtime.evaluate","params":{"objectGroup":"console","includeCommandLineAPI":true,"doNotPauseOnExceptionsAndMuteConsole":true,"expression":"window.location.href","returnByValue":true},id:1}
expression为js,id为标识随意填写
返回结果格式:
{"result":{"result":{"type":"string","value":"百度一下"},"wasThrown":false},"id":1}