Skip to content

Commit 39c33cc

Browse files
ledsunkateinoigakukun
authored andcommitted
Wait for the text/ruby script tag to be read
1 parent 6ec2398 commit 39c33cc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ export const main = async (pkg: { name: string; version: string }) => {
1212

1313
globalThis.rubyVM = vm;
1414

15-
runRubyScriptsInHtml(vm);
15+
// Wait for the text/ruby script tag to be read.
16+
// It may take some time to read ruby+stdlib.wasm
17+
// and DOMContentLoaded has already been fired.
18+
if (document.readyState === "loading") {
19+
document.addEventListener("DOMContentLoaded", () =>
20+
runRubyScriptsInHtml(vm)
21+
);
22+
} else {
23+
runRubyScriptsInHtml(vm);
24+
}
1625
};
1726

1827
const runRubyScriptsInHtml = async (vm) => {

0 commit comments

Comments
 (0)