Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
How do I make custom JavaScript console commands?

I've been trying to make custom console commands with JavaScript with no success. There seem to be no sources about my question.

When I say "JavaScript Console Commands" I mean I'd like to make my own commands from the console. For example, if the visitor types "custom.command()" in my website's console area, I want the output to be: console.log("This is my custom command");.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You don't have to do anything special; just create an object at global scope with functions on it, and the user will be able to use it from the devtools console.

For instance (in a script, not a module):

const custom = {
    command() {
        console.log("This is my custom command.");
    },
};

Because that's at global scope, it creates a global, and so it is accessible in the console when your page is open.

(It doesn't have to be an object; you could just create a function at global scope, but your example usage was using an object.)


If you wanted to do this from a module, since the top level of a module isn't global scope, you'd have to do the same kind of thing you have to do to create a global in a function, which is covered by the answers to this question (in your case, it' basically assign to a property on window: window.custom = { /*...*/ };).

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda