vladimir_1969_2
vladimir_1969_2

Reputation: 111

Browser EventLoop prevents window load event from firing when advanced by an async substlecrypto call

Why is it happening and how to fix it? To reproduce comment/uncomment generateKey call and watch the event handler (you might want to put into a module (which is how I use it) or execute is as part async IIFE - post updated to give the exact repro). The behavior is observed in Chrome v.128.0.6613.138.

Note: wrapping generateKey inside a nested IIFE (and thus lowering its execution priority) * fixes * the event handling, but I need my keys beforehand. I understand that it's a dreadful approach from user experience point of view, but ignoring the registered handler doesn't seem like an adequate measure neither.

(async () => {

    const keys = await window.crypto.subtle.generateKey(
        {
            name: "ECDSA",
            namedCurve: "P-256"
        },
        true,
        ["sign", "verify"]
    );

    window.addEventListener("load", () => {
        debugger;
        console.info("Fired");
    });


})();

Upvotes: 1

Views: 41

Answers (0)

Related Questions