🏠 back to Observable

Ignored call to 'print()'. The document is sandboxed...

Hi,

I have got recently this error in my notebooks: Ignored call to ‘print()’. The document is sandboxed, and the ‘allow-modals’ keyword is not set. What is that? I understand basically, but why is that? :slight_smile: …and how can handle that? Many thanks.
(Chrome Version 90.0.4430.85 (Official Build) (64-bit))

Csaba

You might consider logging to the console, returning a string, setting the text of a DIV, or something else. It’s hard to know what the best option is without more detail on what you’re trying to accomplish.

1 Like

Sorry I was not clear. This is just a simple logging to the console print(x), and x is a simple number javascript variable:
f = {
let x = 3;
print(x);
}
and f is called form an another cell.

When you edit your notebook on observablehq.com, the actual notebook code runs in a sandboxed iframe, which blocks some browser features like print or prompt.

This is intentional, and the only workaround is to run your notebook code directly (either by downloading it, or by using the embed modal to generate the required Javascript code).

Actually, I think there’s a misunderstanding: In Javascript, calling print() opens the browser’s print dialog. If you want to log messages (like you’d do e.g. in Python), you have to call console.log(data) instead.

Yep! console.log() should work just fine from the iframe.