Simulating restarts when debugging cordova applications
Debugging Cordova applications can be performed using browser based debuggers (Chrome for Android, Safari for iOS), whether running in the Cordova browser platform, simulator or from a real device connected via USB.
Often during debugging the application will need to be restarted, which when running from a simulator or a real device would mean that the currently running browser debugger will detach when the app on the device is stopped and will need to be reconnected manually.
As an app on a simulator or device needs to be running before it can be debugged,
re-attaching the debugger can make it hard to debug application start up events
or code. This is especially true when working with iOS as Safari will not remember
items such as
console.log() before the debugger was opened.
window.location.href = '?d=' + (new Date()).getTime();
This will reload the page (the Cordova webview file URL) to the same page with an
addition of a
d parameter, for example "?d=1478957654794". This extra parameter
is to prevent the page from being cached and forcing a page load.
With this method you will now see any start up debugging in place even with iOS and Safari.
The above method can be used with any query string or hash parameters needed in put the application in the state required for a specific debugging task.
Last updated: 12/11/2016