background

As we all know, on the iOS platform, in order to Debug the javascript code running in the WKWebView or JavaScriptCore App, it is generally required to deploy the App project with the Debug configuration on the mobile phone using Xcode. Then use the corresponding option in Safari Developer menu on PC to debug.

The problem

The internal test package and online package of the company are generally packaged with Disrubution or enterprise certificate, and these two packages are often used for on-site troubleshooting. Safari debugging of this package is not supported.

plan

  1. AppIn theThe Debugger moduleAt run timeWKWebVieworJavaScriptCoreObject address by usingWebKitinternalC++ APIAccess its debug message-related interface
    • The input and output of the message interface supportWebKit debugging protocoldata
  2. AppIn aWebSocketThe server that forwards external requests toThe Debugger moduleWhen forwarding, you also need to pass in the externalChrome Debugging ProtocolData conversion toWebKit debugging protocoldata
    • ChrometoWebKitProtocol conversion referenceOpen source implementation of node.js version
  3. PCwithChromeOpen the following address (fill in the correct oneWebSocketThe server’sIPAddress and port number), connectionStep 2In the server, you can achieve real machine debugging.
    chrome-devtools://devtools/bundled/inspector.html? Ws =[IP address]:[port number]
    Copy the code

Finally, welcome everyone to pay attention to my wechat public number, free to communicate more