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

in isJsDom there is no check on navigator.userAgent #28

Open
locustshadow opened this issue Sep 26, 2023 · 1 comment
Open

in isJsDom there is no check on navigator.userAgent #28

locustshadow opened this issue Sep 26, 2023 · 1 comment

Comments

@locustshadow
Copy link

even using 2.1.1 logic, when i run it in node (alpine14), i get the following error:

    (navigator.userAgent.includes("Node.js") ||
                         ^
TypeError: Cannot read property 'includes' of undefined

when i evaluate each part, i can see these various values:
typeof window !== "undefined"
true

window.name === "nodejs"
false

therefore,
(typeof window !== "undefined" && window.name === "nodejs")
is false

so, one would think it would short circuit, but for some reason it continues on to the OR where

typeof navigator !== "undefined"
is true

because

navigator is an object with
{appName: 'nodejs'}

but then it blows up here because there i no userAgent:

navigator.userAgent.includes("Node.js")
Uncaught TypeError TypeError: Cannot read property 'includes' of undefined

so, it seems like the checks are not preventing it from trying to access a property on an undefined object (navigator.userAgent). would appreciate if you could identify a way to make this work for me. we are using bitgo_service which uses your code. not sure how this works for others and not for me, but i can override the dependency of the current bitgo version we are using, if you can create an updated package.

many thanks!

@dabit3
Copy link

dabit3 commented Oct 18, 2023

I also ran into this error, had to polyfill in order to get it to work, if anyone else wants to do the same, just fork it and do this:

const isJsDom =
  (typeof window !== "undefined" && window.name === "nodejs") ||
  (typeof navigator !== "undefined" && navigator.userAgent &&
    (navigator.userAgent.includes("Node.js") ||
      navigator.userAgent.includes("jsdom")));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants