Skip to content

Instantly share code, notes, and snippets.

@Osmiogrzesznik
Created November 8, 2021 16:14
Show Gist options
  • Save Osmiogrzesznik/5eecfa27b822beec70f0a42b3c664a62 to your computer and use it in GitHub Desktop.
Save Osmiogrzesznik/5eecfa27b822beec70f0a42b3c664a62 to your computer and use it in GitHub Desktop.
Quick Dirty D.I.Y. android console for debugging
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();
}
});
}
@Osmiogrzesznik
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment