如何在iOS应用程序WkWebView中调试javascript? [英] How to debug javascript in an iOS app WkWebView?

查看:623
本文介绍了如何在iOS应用程序WkWebView中调试javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,第三方已经将其嵌入到WkWebView中的iOS应用程序中。我的网站上存在一个错误,只有在此应用中查看时才会显示;我不能通过浏览器或我专门为检查错误而构建的单独的iOS应用程序来复制它。为了继续解决这个bug,我需要能够在应用程序中调试实时运行的javascript。如果我有一个应用程序的调试版本,这将非常简单:只需将其连接到Safari的远程调试器,但由于安全限制,应用程序开发人员无法向我发布调试版本。

I have a website that a 3rd party has iframed into their iOS app inside a WkWebView. There is a bug on my site that manifests only when viewed in this app; I cannot replicate it either via a browser or a separate iOS app that I built specifically to check for the bug. In order to proceed with resolving the bug, I need to be able to debug the javascript running in real time in the app. If I had a debug build of the app, this would be trivially easy: just hook it up to Safari's remote debugger, but due to security constraints, the app developer cannot release a debug build to me.

在这些条件下调试javascript有哪些选项?

What options exist to debug javascript under these conditions?


  • 无法更改应用代码

  • 必须至少使用应用程序的发布版本

  • ,查看日志,或者最好公开与浏览器开发者控制台相当的功能:


    • 添加断点

    • 逐步执行代码

    • 查看DOM

    • 查看控制台输出

    • cannot change app code
    • must work with a release build of an app
    • at a minimum, view logs or, preferably, expose capabilities comparable to a browser developer console:
      • add breakpoints
      • step through code
      • view DOM
      • view console outputs

      推荐答案

      您可以将Safari的开发者工具从Mac连接到iOS应用程序。从那里,您可以在Web视图中调试javascript,并查看您在Mac上测试Safari中的任何网站时可以看到的任何内容。

      You can connect Safari's developer tools, from a Mac, to the iOS app. From there, you can debug the javascript within your web view and see anything you could see if you're testing any website in Safari on your Mac.

      高级步骤为:

      • Reproduce issue in your app.
      • Connect device to Mac.
      • Follow steps in Apple documentation: https://developer.apple.com/library/content/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/GettingStarted/GettingStarted.html#//apple_ref/doc/uid/TP40007874-CH2-SW8
      • After connecting the remote debugger from safari on your mac to the iOS app, click the refresh button. It'll force the in-app web view to refresh, so you'll see what went wrong on-load.

      这篇关于如何在iOS应用程序WkWebView中调试javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆