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

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

Open
4 tasks done
vik-buchinski opened this issue May 10, 2024 · 11 comments
Open
4 tasks done
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:browser Related to MSW running in a browser

Comments

@vik-buchinski
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.)

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.

@vik-buchinski vik-buchinski 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 May 10, 2024
@akumapps
Copy link

Same behavior here with version 2.3.0

@kaique64
Copy link

I got the same behavior here with version 2.3.0

@gypz24
Copy link

gypz24 commented Jun 17, 2024

I got the same result

@ByteWither
Copy link

@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
Copy link

Any update regarding this issue?

@Crauzer
Copy link

Crauzer commented Oct 14, 2024

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
Copy link

Marcosld commented Oct 21, 2024

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

@diego-aquino
Copy link

diego-aquino commented Oct 25, 2024

I can confirm that this issue is still happening in [email protected], using the same reproduction created by @vik-buchinski.

image


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

if (!response.url) {
Object.defineProperty(response, 'url', {
value: request.url,
enumerable: true,
writable: false,
})

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

const request = context.requests.get(requestId)!

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

@NullVoxPopuli
Copy link

Present in 2.6.2 as well

@rkambara
Copy link

2.6.4 as well

@artsiomshushkevich
Copy link

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

image

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

No branches or pull requests