Skip to content

Commit 77d1b23

Browse files
authored
Fix Voila IFrame renderer (#1469)
* wip * allow disable iframe sandbox mode * Update config loading logic * Remove sandbox switch button * Remove sandbox option from voila preview iframe
1 parent 264d843 commit 77d1b23

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

packages/jupyterlab-preview/src/preview.tsx

+6-9
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,14 @@ export class VoilaPreview extends DocumentWidget<IFrame, INotebookModel> {
4646
constructor(options: VoilaPreview.IOptions) {
4747
super({
4848
...options,
49-
content: new IFrame({
50-
sandbox: [
51-
'allow-same-origin',
52-
'allow-scripts',
53-
'allow-downloads',
54-
'allow-modals',
55-
'allow-popups'
56-
]
57-
})
49+
content: new IFrame()
5850
});
5951

52+
const iframe = this.content.node.querySelector('iframe');
53+
if (iframe) {
54+
iframe.removeAttribute('sandbox');
55+
}
56+
6057
window.onmessage = (event: any) => {
6158
//console.log("EVENT: ", event);
6259
const level = event?.data?.level;

voila/server_extension.py

+44-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
from jupyter_server.base.handlers import FileFindHandler, path_regex
1515
from jupyter_server.utils import url_path_join
1616
from jupyterlab_server.themes_handler import ThemesHandler
17-
17+
from jupyter_core.paths import jupyter_config_path
18+
from jupyter_server.serverapp import ServerApp
1819
from .tornado.contentshandler import VoilaContentsHandler
19-
20+
from traitlets.config import (
21+
JSONFileConfigLoader,
22+
PyFileConfigLoader,
23+
Config,
24+
ConfigFileNotFound,
25+
)
2026
from .configuration import VoilaConfiguration
2127
from .tornado.handler import TornadoVoilaHandler
2228
from .paths import ROOT, collect_static_paths, collect_template_paths, jupyter_path
@@ -38,10 +44,44 @@ def _jupyter_server_extension_points():
3844
return [{"module": "voila.server_extension"}]
3945

4046

41-
def _load_jupyter_server_extension(server_app):
47+
def load_config_file() -> Config:
48+
"""
49+
Loads voila.json and voila.py config file from current working
50+
directory and other Jupyter paths
51+
"""
52+
53+
new_config = Config()
54+
base_file_name = "voila"
55+
config_file_paths = [*jupyter_config_path(), os.getcwd()]
56+
57+
for current in config_file_paths:
58+
py_loader = PyFileConfigLoader(filename=f"{base_file_name}.py", path=current)
59+
try:
60+
py_config = py_loader.load_config()
61+
new_config.merge(py_config)
62+
except ConfigFileNotFound:
63+
pass
64+
65+
json_loader = JSONFileConfigLoader(
66+
filename=f"{base_file_name}.json", path=current
67+
)
68+
try:
69+
json_config = json_loader.load_config()
70+
new_config.merge(json_config)
71+
except ConfigFileNotFound:
72+
pass
73+
74+
return new_config
75+
76+
77+
def _load_jupyter_server_extension(server_app: ServerApp):
4278
web_app = server_app.web_app
4379
# common configuration options between the server extension and the application
44-
voila_configuration = VoilaConfiguration(parent=server_app)
80+
81+
voila_configuration = VoilaConfiguration(
82+
parent=server_app, config=load_config_file()
83+
)
84+
4585
template_name = voila_configuration.template
4686
template_paths = collect_template_paths(["voila", "nbconvert"], template_name)
4787
static_paths = collect_static_paths(["voila", "nbconvert"], template_name)

0 commit comments

Comments
 (0)