Skip to content

docs: Update custom-worker-script-location.mdx#507

Open
cdaringe wants to merge 1 commit intomswjs:mainfrom
cdaringe:patch-1
Open

docs: Update custom-worker-script-location.mdx#507
cdaringe wants to merge 1 commit intomswjs:mainfrom
cdaringe:patch-1

Conversation

@cdaringe
Copy link

@cdaringe cdaringe commented Nov 3, 2025

problem

I was getting errors and warnings despite setting the Service-Worker-Allowed header.

solution

clarify that you MUST tell MSW about the scope!

# problem

I was getting errors and warnings despite setting the Service-Worker-Allowed header.


# solution

clarify that you MUST tell MSW about the scope!
@vercel
Copy link

vercel bot commented Nov 3, 2025

@cdaringe is attempting to deploy a commit to the MSW Team on Vercel.

A member of the Team first needs to authorize it.

url: '/assets/mockServiceWorker.js',
options: {
// Required if you opt-in to Service-Worker-Allowed header
scope: "YOUR_TARGET_SCOPE",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so the scope option becomes required if you use a custom Service-Worker-Allowed header? I didn't know that.

@cdaringe could you please post what kind of error were you having before this fix? I'd love to learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said errors and warnings, but really just the warning from MSW. It would say that there was a scope of mismatch and to set the header. Well, I set the header and it continued to warn. I thought, maybe I said it on the wrong asset. Nope I sent it on the correct asset, and the warning was sticky. My debugging journey eventually led me to discover that the scope API was even an option in MSW. As soon as I set it, the MSW warning went away. I did not actually confirm that loading behavior was different— I just trusted the warning was correct, and sought to fix it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! Would appreciate if you posted the original warning though. Makes it easier for people to discover this in hindsight. Thanks.

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

Successfully merging this pull request may close these issues.

2 participants