NeilFraser / JS-Interpreter

A sandboxed JavaScript interpreter in JavaScript.
Apache License 2.0
2.01k stars 353 forks source link

console is not defined #279

Closed jcubic closed 1 month ago

jcubic commented 1 month ago

Just found about this project and tried to execute this simple code:

console.log(10 + 10);
console.log(20 + 20);
console.log(20 + 20);

it only step through first statement and when you try to run this code it returns this error in console:

interpreter.js:3358 Uncaught ReferenceError: console is not defined

NeilFraser commented 1 month ago

That's correct. 'console' is not part of JavaScript, it's an API in the browser. JS-Interpreter is a sandbox, it doesn't grant access to random browser APIs.

You will need to either define the 'console' API (the docs have examples of how to create this) or use 'alert' which is an already defined API in the demos.

jcubic commented 1 month ago

Yes, thanks just started reading docs and realized that everything need to be exposed explicitly.