Debug javascript on iphone

Was figuring out why a javascript widget was not working properly on iphones today at work. The widget is a kinda silly information box that display some content in a iframe and the issue turned out to be that you can't set the height of a iframe in mobile safari. It was solved by adding overflow: auto and a -webkit-overflow-scrolling all in all not very interesting.

What I did enjoy was the absolutely horrid hack I used to get my console logs out of the ipoon.

window.onerror = function (msg, url, line) {
    $.ajax('http://my-host:8000/error', {
        data: {
            'message': msg,
            'line': line,
            'url': url
        }
    });
}

console.log = function () {
    var message = Array.prototype.slice.call(arguments).join('');
    if (!message) {
        return;
    }
    $.ajax('http://my-host:8000/log', {
        data: {
            'message': message,
        }
    });
}

And then I could see my console.log's and errors that occurred in the access log of the python3 -m http.server I was using to serve the page already. There's so many cool ways this could be improved and someone has probably already created a full library to do this. But I have a feeling I will leave this as a one of hack with the only trace being this here post.