Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nchevobbe/6c9e2ceb51c388cb8e8b4932419738f8 to your computer and use it in GitHub Desktop.
Save nchevobbe/6c9e2ceb51c388cb8e8b4932419738f8 to your computer and use it in GitHub Desktop.
Fake typing in the console and executing commands, from the browser console
// With the console open, in the browser console:
async function getOpenedConsoleReference() {
var {devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var target = await devtools.TargetFactory.forTab(gBrowser.selectedTab);
var {gDevTools} = devtools.require("devtools/client/framework/devtools");
var toolbox = gDevTools.getToolbox(target);
return toolbox.getCurrentPanel();
}
function sleep(delay) {
return new Promise(res => setTimeout(res, delay));
}
async function typeInConsole(inputs, {
WAIT_BEFORE_TYPING_MS = 1000,
WAIT_BETWEEN_KEYSTROKES = 50,
WAIT_BEFORE_EXECUTE = 200,
WAIT_AFTER_EXECUTE = 1000
} = {}) {
const {hud} = await getOpenedConsoleReference();
hud.ui.clearOutput();
await sleep(WAIT_BEFORE_TYPING_MS);
hud.jsterm._setValue("");
for(const input of inputs) {
for (const char of Array.from(input)) {
hud.jsterm.insertStringAtCursor(char);
await sleep(WAIT_BETWEEN_KEYSTROKES);
}
await sleep(WAIT_BEFORE_EXECUTE);
hud.jsterm.execute();
await sleep(WAIT_AFTER_EXECUTE);
}
}
typeInConsole([
`1 + 1`,
`$_`,
`$_ + 1`
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment