Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get startup console logs in iOS WebView

In a Cordova application, any calls to console.{log,warn,error,etc} before connecting Safari's developer tools do not appear in the console. This makes it impossible to debug startup errors. How do I get those messages?

Bonus question: How do I get the WebView to stop on debugger; lines prior to connecting with Safari?

like image 523
David Souther Avatar asked Sep 12 '14 14:09

David Souther


2 Answers

This simple trick can be useful, just open the console in Safari and run:

window.location.reload()
like image 53
itumb Avatar answered Sep 24 '22 11:09

itumb


I remember a friend telling me about a way to keep safari web inspector running regardless of whether or not the app is in the foreground or not. I found his article and here are the details -

The first thing to do is to set a global hotkey – steps:

  • Open System Preferences / Keyboard
  • On the right panel, select Application Shortcuts
  • Add a hot key – use whatever keys you want (I used CMD + ALT + I)
  • Have the matching key be index.html or whatever your cordova’s main html file is

Steps to keep open SWI

  • Launch Cordova App
  • Open SWI
  • Close SWI
  • Launch SWI with quick key as set up in global hotkey Application Shortcuts
  • Close App
  • Reopen app – notice SWI is still running and continues to give us logging/debugging!

Aside from the technique above have you installed this plugin below and inspected logs in Xcode?

cordova plugin add org.apache.cordova.console

Do you use Ripple Emulator? Here is a great post on setting it up.

like image 27
Ross Avatar answered Sep 22 '22 11:09

Ross