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

TypeError: crypto.randomUUID is not a function with msw 2.2.12 #2111

Closed
4 tasks done
maxime-bc opened this issue Mar 27, 2024 · 3 comments · Fixed by #2113
Closed
4 tasks done

TypeError: crypto.randomUUID is not a function with msw 2.2.12 #2111

maxime-bc opened this issue Mar 27, 2024 · 3 comments · Fixed by #2113
Assignees
Labels
bug Something isn't working scope:browser Related to MSW running in a browser

Comments

@maxime-bc
Copy link

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Browsers

Chromium (Chrome, Brave, etc.), Firefox, Safari

Reproduction repository

https://github.com/maxime-bc/test-msw

Reproduction steps

npm install && npx vite --host 0.0.0.0

Then, try to access the website using both local and network addresses. In the tab accessed by the network address, the error will appear in the console.

Then, downgrade msw to 2.2.11 and start the dev server again:
npm install [email protected] && npx vite --host 0.0.0.0

Again, access the website using both local and network addresses. This time the error will not appear.

Current behavior

Hello,

I'm encountering the following behavior: when accessing a website via its local address, msw works. But when using a network address, the following error is raised in the browser console : TypeError: crypto.randomUUID is not a function.

As far as I understand, this is the intended behavior as crypto.randomUUID is only available in secure contexts, such as localhost.

What I found strange is that prior updating to msw 2.2.12, I was on version 2.1.4 and I never had any issues with crypto.randomUUID, which was introduced in 2.0.0.

I tried version 2.2.11 and had no issues, the error is not raised at all so it seems to be a problem with version 2.2.12 ?

Expected behavior

This error should not be raised ?

@maxime-bc maxime-bc added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:browser Related to MSW running in a browser labels Mar 27, 2024
@maxime-bc maxime-bc changed the title TypeError: crypto.randomUUID is not a function error with msw 2.2.12 TypeError: crypto.randomUUID is not a function with msw 2.2.12 Mar 27, 2024
@kettanaito
Copy link
Member

Hi, @maxime-bc. Thanks for reporting this!

Looks like an oversight on my part. We cannot rely on crypto because it's unavailable in some contexts. TIL. I think this is a good indication we need to migrate to a different ID algorithm.

@kettanaito
Copy link
Member

Opened the fix in the underlying Interceptors package: mswjs/interceptors#536. Will update the dependency in MSW once it's released.

@kettanaito kettanaito removed the needs:triage Issues that have not been investigated yet. label Mar 27, 2024
@kettanaito
Copy link
Member

Released: v2.2.13 🎉

This has been released in v2.2.13!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scope:browser Related to MSW running in a browser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants