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

can't handle request for shared workers #1350

Closed
4 tasks done
njoel24 opened this issue Jul 25, 2022 · 4 comments · Fixed by #1448
Closed
4 tasks done

can't handle request for shared workers #1350

njoel24 opened this issue Jul 25, 2022 · 4 comments · Fixed by #1448
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

@njoel24
Copy link

njoel24 commented Jul 25, 2022

Prerequisites

Environment check

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

Browsers

Chromium (Chrome, Brave, etc.)

Reproduction repository

not available

Reproduction steps

When trying to request a shared worker, the clientId attached to fetch event object is an empty string.

That causes the following line to break under mockServiceWorker.js in resolveMainClient function:
if(client.frameType === 'top-level')

I managed to make it work currently by checking for client like the following:
if(client && client.frameType === 'top-level')

With that I am able to work with shared worker.

Do you have any ideas why that happens?

msw version: 0.44.2

Thanks

Current behavior

the msw fails handling the request

Expected behavior

msw should handle the request.

@njoel24 njoel24 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 Jul 25, 2022
@kettanaito
Copy link
Member

kettanaito commented Jul 25, 2022

Hey, @njoel24.

Could you tell me more about your setup? It's really hard to advise anything without knowing what/how you're trying to do.

This condition is a part of the resolveMainClient logic that tries to look up the actual client that has registered the worker. Since you may have nested clients (i.e. a page embed via iframe), we need to find the top-level client, which is always your application that called worker.start(). It's that client with which the worker must communicate, that client is responsible for request resolution.

I don't have experience with shared workers. I'd be thankful if you contributed an integration test for that, which would reproduce the issue. Until then, I consider this issue closed for the lack of a reproduction scenario.

@njoel24
Copy link
Author

njoel24 commented Jul 25, 2022

Hey @kettanaito ,

thanks for your reply.

In the issue I described there are no iframes involved, it might be something related on how the shared worker requests the resource.

Yes, I will definitely create an integration test for that, so you will have more details.

@njoel24
Copy link
Author

njoel24 commented Jul 27, 2022

hey @kettanaito ,

I created an integration test for the issue: https://github.com/njoel24/integration-test-ms-shared-worker
Just clone, install, run 'npm run build' and run 'npm run start' and run the code on the browser.

Here what the error should be in console:

test results

Please note that the handler has not been implemented and left as null because the error happens before.

Kindly let me know if you need any more information.
I would be more than happy to help.

@kettanaito
Copy link
Member

Released: v0.48.0 🎉

This has been released in v0.48.0!

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.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

Successfully merging a pull request may close this issue.

2 participants