Skip to content
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

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

Open
datvm opened this issue Jun 12, 2024 · 4 comments
Labels
bug Something isn't working more info needed We need more information before we can act on this issue

Comments

@datvm
Copy link

datvm commented Jun 12, 2024

Please see this question here on Microsoft Learn where it's confirmed it is apparently a bug in Microsoft Edge.

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:

image

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.

@datvm datvm added the bug Something isn't working label Jun 12, 2024
@captainbrosset
Copy link
Contributor

Thank you for reporting this here. I have two questions:

  1. Does the bug only appear in the DevTools Console? That is: the value appears as undefined in the Console, but the code works.
  2. Are you able to provide a full code snippet for us to try and reproduce this locally? Right now, the code is incomplete and I can't really run it locally without inventing other parts of the code, which might not be the right ones to reproduce the issue.

Thank you.

@captainbrosset captainbrosset added the more info needed We need more information before we can act on this issue label Jun 17, 2024
@datvm
Copy link
Author

datvm commented Jun 17, 2024

@captainbrosset Hi,

  1. No, the DevTool tooltip is the only place where the should-be value shows up. However, the "real" value is still undefined, making my if statement's expression false when it should be true. That is, the code doesn't perform as it should.

  2. I sent it to the person at this post privately because it's a private project. Unfortunately I am not sure what causes it and cannot make a minimal reproducible example. If you provide a private channel I will send over the file.

@captainbrosset
Copy link
Contributor

@datvm if you can, please send the file over as a private message either on my twitter or mastodon account, which are linked to from my github account page: https://github.com/captainbrosset/
Or send it as an email: patrickbrosset at gmail dot com.

@datvm
Copy link
Author

datvm commented Jun 28, 2024

@captainbrosset thanks, sent you an email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working more info needed We need more information before we can act on this issue
Projects
None yet
Development

No branches or pull requests

2 participants