[UIWebView] Enable logging of JavaScript errors to the app (system) log

Originator:radexpl
Number:rdar://27762261 Date Originated:09-Aug-2016 10:59 AM
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification:Feature (New) Reproducible:Not Applicable
 
JavaScript `console.log`s, exceptions, and errors are not logged to the app (system) log.

They only exist in their own web console log. This makes it cumbersome to view them in apps that use web views, because we have to *first* connect to the web view using Web Inspector, and only then we can reproduce an issue, or observe an important diagnostic log or other web view error. (With UIWebView, web view logs are not stored when not looked at through the web inspector, which makes it hard to capture errors that happen at web view’s startup.)

It should be possible to enable, perhaps as a development/diagnostic switch, redirecting of all web view logs and errors to the system log, so one can see them in Xcode pane or on devices through the system log.

(With WKWebView, there already exists a private API: _logsPageMessagesToSystemConsoleEnabled on WKPreferences to allow this. In rdar://27762233 I suggested to make this API public. For UIWebView, there’s no such equivalent as far as I’m aware. It is possible to use a private API to get to a JSContext to do this, but there ought to be a clean, sanctioned way to do this.)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!