Skip to content

Instantly share code, notes, and snippets.

@wlib
Last active March 31, 2019 20:58
Show Gist options
  • Save wlib/085ec2697972a88b4f1f806d794f5bb6 to your computer and use it in GitHub Desktop.
Save wlib/085ec2697972a88b4f1f806d794f5bb6 to your computer and use it in GitHub Desktop.
Ultra simple js console for when devtools are blocked
window.jsConsoleState = {
lines: ["This is a JavaScript console.\nTo clear history, run clear()\nTo exit, run exit()"],
isLooping: true
}
const jsConsole = () => {
// Show the previous lines above the prompt
const input = prompt(window.jsConsoleState.lines.join("\n"))
// Push user input for next prompt
window.jsConsoleState.lines.push(input)
// Evaluate user input
let result
try {
result = window.eval(input)
} catch (err) {
result = err
}
// Quit execution if the user exited
if (!window.jsConsoleState.isLooping) {
return
} else {
// Push the evaluation return value and then display the next prompt
window.jsConsoleState.lines.push("> " + result)
jsConsole()
}
}
window.exit = () => {
window.jsConsoleState.isLooping = false
}
window.clear = () => {
window.jsConsoleState.lines = []
}
// Initiate
jsConsole()
javascript:document.body.appendChild(document.createElement('script')).src='https://cdn.staticaly.com/gist/wlib/085ec2697972a88b4f1f806d794f5bb6/raw/e8924a773f848923dd5d77175e6e9c0bf8fa514a/jsconsole.js';void(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment