-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
help: small demo page #26
Comments
<!DOCTYPE html>
<html>
<head>
<script type="module">
import Viz from "https://unpkg.com/@aduh95/viz.js";
const locateFile = (fileName) =>
"https://unpkg.com/@aduh95/viz.js/dist/" + fileName;
const onmessage = async function (event) {
if (this.messageHandler === undefined) {
// Lazy loading actual handler
const { default: init, onmessage } = await import(
Module.locateFile("render.browser.js")
);
// Removing default MessageEvent handler
removeEventListener("message", onmessage);
await init(Module);
this.messageHandler = onmessage;
}
return this.messageHandler(event);
};
const vizOptions = {
workerURL: URL.createObjectURL(
new Blob(
[
"const Module = { locateFile:",
locateFile.toString(),
"};",
"onmessage=",
onmessage.toString(),
],
{ type: "application/javascript" }
)
),
};
let viz;
const input = document.getElementById("dot");
const output = document.getElementById("diag");
function update() {
output.innerHTML = "Loading...";
viz ??= new Viz(vizOptions);
return viz
.renderString(input.value)
.then((svgString) => {
output.innerHTML = svgString;
})
.catch((error) => {
console.error(error);
output.innerHTML = 'An error occurred';
});
}
input.addEventListener("input", update);
update().then(() => {
input.disabled = false;
input.focus();
});
</script>
</head>
<body>
<textarea id="dot" disabled>digraph{ A -> B; }</textarea>
<p>let's diag</p>
<output id="diag"></output>
</body>
</html> |
Hi, Thanks a lot for your help The proposal looks good. I think I was close to that at some point. And I got the same result as the given code : Searching the web for that error gave me not hint. I've tried with HTTPS and a fresh blocker-free browser profile. But same error 😢 |
I can see this error as well when I try to open this file directly, using a local webserver does fix the error (try |
Since I'm also using a webserver ( The web does not help much, only old issues that are supposed to be fixed in recent FF... |
Ah yes, it looks like that Firefox support for ES modules in Worker is not 100% (https://caniuse.com/mdn-api_worker_worker_ecmascript_modules), which might explain why dynamic imports are disabled in worker scope – or maybe it's a bug in Firefox, not sure. FWIW I've tested that it's working on Safari and Chromium. |
Thank you very much for the investigation. I'll eagerly wait for the resolution of this bug on Firefox. In the meantime, I've written a snippet working with the last non WASM version of viz.js (2.1.2). |
I try to make a simple web page that : loads viz.js, put some dot in a textarea, have a button to render the diagram and put the result in a div.
I've tried
main.cdn.js
is basically what is proposed in the README.I've tried many ways (declare my code as a module, use export, etc.).
But I always end up with
Uncaught ReferenceError: dot2svg is not defined
.Can someone please a small demo page ?
The text was updated successfully, but these errors were encountered: