Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
Chrome extension: execute something in JS console

I build an extension (my pet project) where I click on name of snippet and it will automatically add it to console. I'm stuck because when I use console.log my snippets is already "entered" and after invoking that function it shows reference error: enter image description here

The point is - how to write something into a console using event to "paste snippet" without hitting enter?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You'll want to eval the output you're logging as well (but that can be very dangerous with uncontrolled input).

For example:

const testFunctionText = `var test = () => console.log(1)`

console.log(testFunctionText)
eval(testFunctionText)

document.getElementById("run").onclick = () => {
    eval(document.getElementById("input").value)
}
<input id="input" placeholder="Evaluate console statement (no input on StackOverflow)">
<button id="run">Run</button>

With this code snippet, try putting test() into the provided input.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda