fix: add error listeners + WASM test page

This commit is contained in:
Accusys
2026-05-18 11:48:29 +08:00
parent 4f35386bb1
commit e53106f7e2
2 changed files with 37 additions and 0 deletions

View File

@@ -31,6 +31,14 @@ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-
</style>
</head>
<body>
<script>
window.addEventListener('error', function(e) {
document.getElementById('content').innerHTML = '<p style="color:red">Global error: ' + e.message + '</p>';
});
window.addEventListener('unhandledrejection', function(e) {
document.getElementById('content').innerHTML = '<p style="color:red">Unhandled: ' + e.reason + '</p>';
});
</script>
<script src="/doc-wasm/pkg/md_wasm.js"></script>
<div id="app">
<div class="sidebar">

View File

@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head><title>WASM Test</title></head>
<body>
<h1>WASM Render Test</h1>
<div id="output">Loading...</div>
<div id="output2"></div>
<script src="/doc-wasm/pkg/md_wasm.js"></script>
<script>
async function test() {
const out = document.getElementById('output');
try {
out.textContent = 'Calling wasm_bindgen...';
const wasm = await wasm_bindgen();
out.textContent = 'WASM loaded, testing render...';
const html = wasm.render('# Hello\nThis is **markdown**');
out.innerHTML = html;
document.getElementById('output2').textContent = 'Render worked! Length: ' + html.length;
} catch(e) {
out.innerHTML = '<p style="color:red">Error: ' + e.message + '</p>';
document.getElementById('output2').textContent = e.stack;
}
}
test();
</script>
</body>
</html>