Skip to content

Commit aa17bff

Browse files
committed
treat any html output with script tag as an iframe; fixes #4992 and probably many other things -- matplotlib.animation.ArtistAnimation.to_jshtml() output does not appear
- and probably breaks something too.
1 parent f605514 commit aa17bff

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/packages/jupyter/blobs/iframe.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const MAX_HTML_SIZE = 10 ** 6;
1919
// We use iframes to render html in a number of cases:
2020
// - if it starts with iframe
2121
// - if it has a whole page doctype
22-
// - if it has a <script> tag anywhere without a type -- since those are ignored by safe HTML
22+
// - if it has a <script> tag anywhere -- since those are ignored by safe HTML
2323
// rendering; using an iframe is the only way. This e.g., makes mpld3 work uses -- <script>! https://github.com/sagemathinc/cocalc/issues/1934
2424
// and altair -- https://github.com/sagemathinc/cocalc/issues/4468 -- uses <script type="text/javascript"/>
2525
// - do NOT just render all html in an iframe, e.g., this would break bokeh, since one output creates the target elt,
@@ -46,8 +46,11 @@ export function is_likely_iframe(content: string): boolean {
4646
content.startsWith("<iframe") ||
4747
content.includes("<!doctype html>") ||
4848
(content.includes("<html>") && content.includes("<head>")) ||
49-
content.includes("<script>") ||
50-
content.includes('<script type="text/javascript">')
49+
// this gets really serious -- we sanitize out script tags in non-iframe html,
50+
// and a LOT of interesting jupyter outputs are self contained html + script tags... so
51+
// by rendering them all in iframes (1) they suddenly all work, which is great, and
52+
// (2) if they are large (which is common) they work even better, by far!
53+
content.includes("<script")
5154
);
5255
}
5356

0 commit comments

Comments
 (0)