Reputation: 2258
I know that you can view the console of a cordova app on the browser and through adb.
But what I want is for the user to be able to send me an error report. Within that error report I would like there to be the contents including the console.error that arises.
Any chance this is possible?
Upvotes: 1
Views: 1210
Reputation: 2372
At minimum you would need to:
Add a window.onerror
handler. It will be triggered by any unhandled exceptions in your app. (This does nothing for caught errors, though.) See https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror for more information.
Add some method for sending the error report. You can accomplish this with HTML and a little JavaScript (with XHR). Be sure that the backend you're using is secured.
A more comprehensive option would give you more useful information:
Create a logging method that handles all your app's logging needs. It should be able to handle log levels like info
, warn
, error
, etc. The logging method should save the recent logs so that they can be included in any error reports.
NOTE: You probably don't want to save everything, since that could be memory intensive. You may only want to track the last 100 or so logs entries.
Should an error
occur, have your logger ask the user to send the error report using a reporting method (as in the prior section). Because you've logged additional data, you can include a much more thorough accounting of what's happened in the app to this point.
Ultimately, though, I would look around for an error-handling and reporting library so that you don't need to reinvent the wheel.
NOTE: In all cases you should be careful what you log and where and how you send that data. You shouldn't log anything that would compromise privacy or security (e.g., passwords), and you should send the logs over secured channels and store the logs on your backend securely. You should mention how you store and handle this information (including what information is collected) in your privacy policy as well.
Upvotes: 3