|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import sys |
3 | 4 | import atexit |
4 | 5 | import contextlib |
5 | 6 | import html |
@@ -36,14 +37,20 @@ def room_html(url: str, token: str, *, width: str, height: str) -> HTML: |
36 | 37 | html_text = html_text.replace(token_placeholder, token) |
37 | 38 | html_text = html_text.replace(url_placeholder, url) |
38 | 39 |
|
39 | | - escaped_content = html.escape(html_text, quote=True) |
40 | | - # the extra space in the iframe_html is to avoid IPython suggesting to use IFrame instead. |
41 | | - # it isn't possible in our case, as we need to use srcdoc. |
42 | | - iframe_html = ( |
43 | | - f' <iframe width="{width}" height="{height}" frameborder="0" ' |
44 | | - f'srcdoc="{escaped_content}"></iframe>' |
45 | | - ) |
46 | | - return HTML(iframe_html) |
| 40 | + IN_COLAB = "google.colab" in sys.modules |
| 41 | + |
| 42 | + # Colab output already runs inside an iframe, so we don’t need to create an additional one. |
| 43 | + # It also injects code into this iframe to handle microphone usage, so we need to preserve it. |
| 44 | + if not IN_COLAB: |
| 45 | + escaped_content = html.escape(html_text, quote=True) |
| 46 | + # the extra space in the iframe_html is to avoid IPython suggesting to use IFrame instead. |
| 47 | + # it isn't possible in our case, as we need to use srcdoc. |
| 48 | + html_text = ( |
| 49 | + f' <iframe width="{width}" height="{height}" frameborder="0" ' |
| 50 | + f'srcdoc="{escaped_content}"></iframe>' |
| 51 | + ) |
| 52 | + |
| 53 | + return HTML(html_text) |
47 | 54 |
|
48 | 55 |
|
49 | 56 | def display_room(url: str, token: str, *, width: str = "100%", height: str = "110px") -> None: |
|
0 commit comments