How can I set sandbox="allow-modals" within the HTML viewer widget?

I have created an jupyterlab extension to load a particular type of HTML files. These HTML files are being rendered within jupyterlab with the help of the default jupyterlab HTML viewer extension (with Trust HTML command being enabled by default).

Now I want to enable Copy API within the HTML files. But I am getting the following permission errors

Ignored call to ‘alert()’. The document is sandboxed, and the ‘allow-modals’ keyword is not set.

Uncaught (in promise) DOMException: The Clipboard API has been blocked because of a permissions policy applied to the current document. See Deprecating Permissions in Cross-Origin Iframes - The Chromium Projects for more details.

How can I add sandbox=“allow-modals” so that copy functionality works within the HTML viewer iframe?

If you can get a handle on the iframe widget itself (either by creating it, or finding it with the tracker), you can set the sandbox attribute directly.

1 Like