I’d like to be able to use window.print(). I’m trying to call it from a panel extension and NOT inside an iframe or hidden window. However, when I attempt to make that call chrome throws an error in the console:
Ignored call to ‘print()’. The document is sandboxed, and the ‘allow-modals’ keyword is not set.
In Chrome, sandboxed iframes block modal dialogs by default to prevent them from popping up modal messages to users. This includes window.alert(), window.confirm(), window.print() and window.prompt(). To allow modal dialogs inside “sandboxed iframes” you can add “allow-modals” to the “sandbox” attribute. By default, it looks like my undeployed extension has:
allow-forms allow-scripts allow-same-origin
and does not have “allow-modals”
When I look at deployed extensions I can see that they have:
allow-forms allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox
It’s unclear to me if the production iframe will remain fully sandboxed after it’s accepted, or if you can ask for some restrictions to be lifted as a part of the deployment process.
Also, print functionality may fall under section 2.3 of the guidelines, but it seems like providing users with the ability to print something like a shipping label is harmless.
Has anyone tried to do something like this? Is there a way to get around limitations to window.print()?
If allow-popups is enabled, wouldn’t that imply that I need to open a window in the background and trigger the print event from there? Has anyone done something like that with a panel extension?