JS variable assigned a value is always undefined in Microsoft Edge, but not in Google Chrome

Luke Vo 1 Reputation point
2024-06-10T04:23:29.7766667+00:00

I am encountering an issue where a variable is assigned a value, but the value is always undefined in Microsoft Edge. Strangely, the same code works as expected in Google Chrome. I have confirmed the assigned value is not undefined, and checked that the code does not have any way to assign undefined to the variable. Even though hovering over the variable in DevTools shows the correct value, evaluating the variable in the console still results in undefined. Here is the relevant code:

customElements.define("popup-page", class extends HTMLElement {
    // ...
    #lastDownload = 0;
    // ...

    async #download() {
        // ...
        this.#lastDownload = 0;
        // ...

            for (let i = 0; i < urls.length; i++) {
                // ...
                const id = el.downloadId = await this.#attemptItemAsync(url, maxCon, addDelay);
            }
    }

async #attemptItemAsync(url, maxCon, addDelay) {
        try {
            if (addDelay > 0) {
                const now = Date.now();
                if (now - this.#lastDownload < addDelay) {
                    await sleepAsync(now - this.#lastDownload);
                }
                this.#lastDownload = now;
            }
            
            // ...
        }
        catch {
            return;
        }
    }
});

I believe this is a bug in Microsoft Edge. When I sideloaded the same extension into Google Chrome, the bug did not occur. Please let me know if you need more information.

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,366 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ShiJieLi-MSFT 10,281 Reputation points Microsoft Vendor
    2024-06-12T02:24:40.5866667+00:00

    Hi @Luke Vo,

    Thank you for the code. I can successfully reproduce this problem on every channel of Microsoft Edge, but not on Chrome. To me it seems to be a problem that is unknown to Dev Team since higher versions of Edge still has this problem. You can stick to the quick fix first, and submit feedback here to make Dev Team aware of this issue. Hopefully they will bring the change to the next releases.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    Shijie Li


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.