Created
November 8, 2021 16:14
-
-
Save Osmiogrzesznik/5eecfa27b822beec70f0a42b3c664a62 to your computer and use it in GitHub Desktop.
Quick Dirty D.I.Y. android console for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ((/android/gi).test(navigator.appVersion)) { | |
console = { | |
"_log": [], | |
"log": function (...params) { | |
let arr = params.map(x => JSON.stringify(x)) | |
this._log.push("LOG:" + arr.join(" ")); | |
}, | |
"warn": function (...params) { | |
let arr = params.map(x => JSON.stringify(x)) | |
this._log.push("WARN:" + arr.join(" ")); | |
}, | |
"error": function (...params) { | |
let arr = params.map(x => JSON.stringify(x)) | |
this._log.push("ERR:" + arr.join(" ")); | |
}, | |
"show": function (uuu) { | |
let message = uuu | |
if (!message) { | |
message = this._log.join("\n") | |
} | |
let xxx = prompt(message, "localStorage"); | |
this._log = []; | |
if (xxx) { | |
return this.show(JSON.stringify(eval(xxx), null, 1)); | |
} | |
} | |
}; | |
window.onerror = function (msg, url, line) { | |
console.log("ERROR: \"" + msg + "\" at \"" + "\", line " + line); | |
} | |
window.addEventListener("touchstart", function (e) { | |
if (e.touches.length >= 3 && console._log.length) { | |
console.show(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on https://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/
press with 3 or more fingers to view console output in alert popup, enter code in prompt to be evaluated