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:

The point is - how to write something into a console using event to "paste snippet" without hitting enter?
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.