Skip to content

Instantly share code, notes, and snippets.

Last active September 18, 2017 22:13
Show Gist options
  • Save ejdyksen/6615470 to your computer and use it in GitHub Desktop.
Save ejdyksen/6615470 to your computer and use it in GitHub Desktop.
A tool for getting at a JS console when there is none available.
<div id="consolelog" style="font-family: 'Courier New', Courier, monospace; font-size: 12px; margin: 40px 30px 0px; background-color: white; border: 2px solid black; padding: 10px;"></div>
<input type="text" id="consoleinput" style="margin: 0px 30px; width: 400px;" onkeypress="return evalConsoleInput(event, this.value);" />
<script type="text/javascript">
var appendConsole = function(message, type) {
var color = "black";
if (type === "error") {
color = "red";
} else if (type === "debug") {
color = "blue";
var div = document.createElement('div'); = color; = "10px";
div.innerHTML = message;
var originalConsole = null;
if (window.console != null) {
originalConsole = window.console;
window.console = {
log: function(message) {
appendConsole(message, "info");
info: function(message) {
appendConsole(message, "info");;
debug: function(message) {
appendConsole(message, "debug");
error: function(message) {
appendConsole(message, "error");
function evalConsoleInput(e, message)
if (e.keyCode == 13) { // 13 is the keycode for the enter key
var inputField = document.getElementById("consoleinput");
var evalString = inputField.value;
console.log("> " + evalString);
try {
var returnValue = eval(evalString);
} catch (e) {
} finally {
inputField.value = "";
Copy link

Had you considered using Weinre for remote debugging? I've been using this for debugging PhoneGap applications whilst they're running natively on a device.

Copy link

ejdyksen commented Mar 2, 2014

@danharper I would have loved to use something more sophisticated, but I didn't have network access to the browser session at all from my development machine (odd as that seems).

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