Skip to content

Commit

Permalink
warn on missing needed browser features in example index pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddlingbits committed Mar 24, 2024
1 parent c9d9306 commit ee98729
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
22 changes: 16 additions & 6 deletions examples/index-file.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<!doctype html>
<head>
<title>Examples using tiny-wasm-runtime</title>

<script>
if (!HTMLScriptElement.supports('importmap')) {
} document.getElementById("errorMsg").innerHTML ="THIS BROWSER DOES NOT SUPPORT script type='importmap'. These demos will not work.";
</script>
</head>
<body style="margin: 30px;font-family: Arial, Helvetica, sans-serif;">

<br>
<h1>Examples</h1>
<h2>Using tiny-wasm-runtime</h2>
<div id="errorMsg" style="color: red"></div>
<p>File (unbundled) version</p>
<p>Use the browser back arrow to return to this menu from an example</p>
<div id="errorMsg"></div>
<br>
<a href="helloworld/index.html">hello world</a>
<br>
Expand All @@ -37,6 +32,21 @@ <h2>Using tiny-wasm-runtime</h2>
<a href="tests/index.html">Run tiny-wasm-runtime unit tests</a>
<br><br>
<a href="index.html">Switch to the bundled examples</a>

<script>
if (!this["WebAssembly"])
document.getElementById("errorMsg").innerHTML+= "ERROR: This browser does not support Web Assembly. <br>";

if (!HTMLScriptElement.supports('importmap'))
document.getElementById("errorMsg").innerHTML+="ERROR: This browser does not support script type='importmap'. These demos will not work. <br>";

if (!crossOriginIsolated && !(window.location.protocol === 'file:'))
document.getElementById("errorMsg").innerHTML+= "WARNING: twrWasmModuleAsync examples need crossOriginIsolated. See tiny-wasm-runtime or SharedArrayBuffer docs. <br>";

if (!this["SharedArrayBuffer"])
document.getElementById("errorMsg").innerHTML+= "WARNING: twrWasmModuleAsync examples use SharedArrayBuffer but SharedArrayBuffer is not available in this browser. See tiny-wasm-runtime or SharedArrayBuffer docs. <br>";
</script>

</body>
</html>

13 changes: 13 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<br>
<h1>Examples</h1>
<h2>Using tiny-wasm-runtime</h2>
<div id="errorMsg" style="color: red"></div>
<p>Bundled version</p>
<p>Use the browser back arrow to return to this menu from an example</p>
<br>
Expand All @@ -30,6 +31,18 @@ <h2>Using tiny-wasm-runtime</h2>
<a href="tests/dist/index.html">Run tiny-wasm-runtime unit tests</a>
<br><br>
<a href="index-file.html">Switch to the unbundled examples</a>

<script>
if (!this["WebAssembly"])
document.getElementById("errorMsg").innerHTML+= "ERROR: This browser does not support Web Assembly. <br>";

if (!crossOriginIsolated && !(window.location.protocol === 'file:'))
document.getElementById("errorMsg").innerHTML+= "WARNING: twrWasmModuleAsync examples need crossOriginIsolated. See tiny-wasm-runtime or SharedArrayBuffer docs. <br>";

if (!this["SharedArrayBuffer"])
document.getElementById("errorMsg").innerHTML+= "WARNING: twrWasmModuleAsync examples use SharedArrayBuffer but SharedArrayBuffer is not available in this browser. See tiny-wasm-runtime or SharedArrayBuffer docs. <br>";
</script>

</body>
</html>

0 comments on commit ee98729

Please sign in to comment.