Skip to content

Commit c477e30

Browse files
committed
WASM REPL: show error message when SharedArrayBuffer is not available
1 parent 9a26d70 commit c477e30

1 file changed

Lines changed: 54 additions & 17 deletions

File tree

Tools/wasm/emscripten/web_example/index.html

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
#info {
2929
padding-top: 20px;
3030
}
31+
.error {
32+
border: 1px solid red;
33+
background-color: #ffd9d9;
34+
padding: 5px;
35+
margin-top: 20px;
36+
}
3137
.button-container {
3238
display: flex;
3339
justify-content: end;
@@ -633,24 +639,55 @@
633639
</script>
634640
</head>
635641
<body>
636-
<h1>Simple REPL for Python WASM</h1>
637-
<div id="editor">print('Welcome to WASM!')</div>
638-
<div class="button-container">
639-
<button id="run" disabled>Run code</button>
640-
<button id="repl" disabled>Start REPL</button>
641-
<button id="stop" disabled>Stop</button>
642-
<button id="clear" disabled>Clear</button>
642+
<div id="repldemo">
643+
<h1>Simple REPL for Python WASM</h1>
644+
<div id="editor">print('Welcome to WASM!')</div>
645+
<div class="button-container">
646+
<button id="run" disabled>Run code</button>
647+
<button id="repl" disabled>Start REPL</button>
648+
<button id="stop" disabled>Stop</button>
649+
<button id="clear" disabled>Clear</button>
650+
</div>
651+
<div id="terminal"></div>
652+
<div id="info">
653+
The simple REPL provides a limited Python experience in the
654+
browser.
655+
<a
656+
href="https://github.com/python/cpython/blob/main/Tools/wasm/README.md"
657+
>
658+
Tools/wasm/README.md
659+
</a>
660+
contains a list of known limitations and issues. Networking,
661+
subprocesses, and threading are not available.
662+
</div>
643663
</div>
644-
<div id="terminal"></div>
645-
<div id="info">
646-
The simple REPL provides a limited Python experience in the browser.
647-
<a
648-
href="https://github.com/python/cpython/blob/main/Tools/wasm/README.md"
649-
>
650-
Tools/wasm/README.md
651-
</a>
652-
contains a list of known limitations and issues. Networking,
653-
subprocesses, and threading are not available.
664+
<div id="buffererror" class="error" style="display: none">
665+
<p>
666+
<code>SharedArrayBuffer</code>, which is required for this demo,
667+
is not available in your browser environment. One common cause
668+
of this failure is loading <code>index.html</code> directly in
669+
your browser instead of using <code>server.py</code> as
670+
described in
671+
<a
672+
href="https://github.com/python/cpython/blob/main/Tools/wasm/README.md#the-web-example"
673+
>
674+
Tools/wasm/README.md
675+
</a>.
676+
</p>
677+
<p>
678+
For more details about security requirements for
679+
<code>SharedArrayBuffer</code>, see
680+
<a
681+
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements"
682+
>this MDN page</a
683+
>.
684+
</p>
685+
<script>
686+
if (typeof SharedArrayBuffer === 'undefined') {
687+
document.getElementById('repldemo').style.display = 'none';
688+
document.getElementById('buffererror').style.display = 'block';
689+
}
690+
</script>
654691
</div>
655692
</body>
656693
</html>

0 commit comments

Comments
 (0)