mswjs / msw

Industry standard API mocking for JavaScript.
https://mswjs.io
MIT License
16k stars 522 forks source link

'Cannot read properties of undefined (reading 'url')' when multiple browser tabs are open #2146

Open vik-buchinski opened 6 months ago

vik-buchinski commented 6 months ago

Prerequisites

Environment check

Browsers

Chromium (Chrome, Brave, etc.)

Reproduction repository

https://github.com/hal-shin/msw-bug

Reproduction steps

  1. install nodejs v20.12.2
  2. npm i
  3. npm start
  4. open 2 tabs 'http://localhost:3000/'
  5. after opening the second tab, you'll see the following error: image

Current behavior

when the second tab opened, I see 'Cannot read properties of undefined (reading 'url')' error.

Affected versions: >2.1.7 Versions that work correctly: <= 2.1.7

Expected behavior

application should continue working when it is opened in 2 tabs.

akumapps commented 6 months ago

Same behavior here with version 2.3.0

kaique64 commented 5 months ago

I got the same behavior here with version 2.3.0

gypz24 commented 5 months ago

I got the same result

ByteWither commented 5 months ago

@kettanaito Hi! I find this PR #2031. I think it is a reason of this bug. Can you fix it? Also, I still get error with version 2.3.1 :(

PedroBarbosaSw commented 2 months ago

Any update regarding this issue?

Crauzer commented 1 month ago

This is also happening on the latest version 2.4.11, when multiple tabs of the same origin are open, this error shows up once for each open tab.

The service worker also crashes when you reload the page multiple times: image

Marcosld commented 1 month ago

We are having this problem in our project. It breaks our screenshot/acceptance tests :(

diego-aquino commented 1 month ago

I can confirm that this issue is still happening in msw@2.5.1, using the same reproduction created by @vik-buchinski.

image


It looks like request is getting undefined and line 58 throws:

https://github.com/mswjs/msw/blob/9dc2d71199021c62ad8926555c0313d3b1bd6995/src/browser/setupWorker/start/createResponseListener.ts#L56-L61

request comes from a map and in fact can be undefined, but the code uses a non-null assertion (!).

https://github.com/mswjs/msw/blob/9dc2d71199021c62ad8926555c0313d3b1bd6995/src/browser/setupWorker/start/createResponseListener.ts#L21

I have no deep knowledge of this function, but maybe msw needs to check if request exists before using it?

NullVoxPopuli commented 2 weeks ago

Present in 2.6.2 as well

rkambara commented 1 week ago

2.6.4 as well

artsiomshushkevich commented 1 week ago

Hi msw v2.6.5 also has this issue but in a different place. Please have a look

image