G
G
Gluck Virtualen2016-05-17 12:30:25
JavaScript
Gluck Virtualen, 2016-05-17 12:30:25

How to send visitor browser console log to developer?

There is a JS web application with all the necessary personal belongings: AppCache, WebSQL and all that. Not the most difficult, lines that way for a couple of thousand.
The user complains that something does not work for him. The reasons for this can occur anywhere in the code, and this place will either throw an exception or give an error to the console.
How would I make it so that the console log for the last X minutes is sent to the developers when the user clicks on a special button?
Or even better: only what the developers indicate in advance was sent: potentially problematic places, uncaught errors, etc.?
Only interested in mobile Safari and mobile Chrome, other browsers are not needed.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2016-05-17
@sergey-gornostaev

I don’t know how to send a log on a button click, and if the error is critical, then it is likely that the js on the page is no longer working and no button clicks will be processed. I intercept and log all frontend errors on the backend. Before all the scripts connect on the page is https://github.com/darcyclarke/Detect.js and this

window.onerror = function(err, url, line, col, msg) {
    var data = {
        'Error': err,
        'URL': url,
        'Line': line,
        'Column': null,
        'Message': null,
        'Browser': null,
        'OS': null,
        'Device': null
    };

    // HTML5 only
    data['Column'] = !col ? '' : col;
    data['Message'] = !msg ? '' : msg;

    try {
        var ua = detect.parse(navigator.userAgent); 
        data['Browser'] = !ua.browser.name ? '' : ua.browser.name;
        data['OS'] = !ua.os.name ? '' : ua.os.name;
        data['Device'] = !ua.device.name ? '' : ua.device.name;
    }
    catch(e) {}

    console.groupCollapsed('Error: ' + data['Error']);
    console.log('URL: ' + data['URL']);
    console.log('Line: ' + data['Line']);
    if(data['Column'])
        console.log('Column: ' + data['Column']);
    if(data['Message'])
        console.log('Message: ' + data['Message']);
    console.groupEnd();

    try {
        $.post('/frontend/error/', data);
    }
    catch(e) {}

    return true; //suppressErrorAlert
};

and set up a handler on the server that saves received errors to a file.

D
Dmitry, 2016-05-17
@dimasmagadan

stackoverflow.com/questions/11849562/how-to-save-t...

E
evnuh, 2016-05-17
@evnuh

In your case, you can only redefine the console object and, in addition to outputting to the console, write lines to an array, and when the button is pressed, send this array to the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question