Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!