|
2 | 2 | import json
|
3 | 3 | from typing import Any
|
4 | 4 | from urllib.parse import urlparse
|
5 |
| -from IPython import display as _ipy_display |
6 | 5 |
|
7 | 6 |
|
8 | 7 | def display(kind: str, *args: Any, **kwargs: Any) -> Any:
|
@@ -31,29 +30,26 @@ def __init__(self, url: str) -> None:
|
31 | 30 | {"host": parsed_url.netloc, "protocol": parsed_url.scheme + ":"}
|
32 | 31 | )
|
33 | 32 | self._path = parsed_url.path
|
34 |
| - _ipy_display.display_html( |
35 |
| - "<script>document.idomServerExists = true;</script>", raw=True, |
36 |
| - ) |
37 | 33 |
|
38 | 34 | def _script(self, mount_id):
|
39 | 35 | return f"""
|
40 | 36 | <script type="module">
|
| 37 | + const loc = {self._location}; |
| 38 | + const idom_url = "//" + loc.host + "{self._path}"; |
| 39 | + const http_proto = loc.protocol; |
| 40 | + const ws_proto = (http_proto === "https:") ? "wss:" : "ws:"; |
41 | 41 | // we want to avoid making this request (in case of CORS)
|
42 | 42 | // unless we know an IDOM server is expected to respond
|
43 |
| - if (document.idomServerExists) {{ |
44 |
| - const loc = {self._location}; |
45 |
| - const idom_url = "//" + loc.host + "{self._path}"; |
46 |
| - const http_proto = loc.protocol; |
47 |
| - const ws_proto = (http_proto === "https:") ? "wss:" : "ws:"; |
| 43 | + fetch(http_proto + idom_url, {{mode: "no-cors"}}).then(rsp => {{ |
48 | 44 | import(http_proto + idom_url + "/client/core_modules/layout.js").then(
|
49 | 45 | (module) => {{
|
50 |
| - module.renderLayout( |
51 |
| - document.getElementById("{mount_id}"), |
52 |
| - ws_proto + idom_url + "/stream" |
53 |
| - ); |
| 46 | + module.renderLayout( |
| 47 | + document.getElementById("{mount_id}"), |
| 48 | + ws_proto + idom_url + "/stream" |
| 49 | + ); |
54 | 50 | }}
|
55 | 51 | );
|
56 |
| - }} |
| 52 | + }}); |
57 | 53 | </script>
|
58 | 54 | """
|
59 | 55 |
|
|
0 commit comments