docs: Update custom-worker-script-location.mdx#507
docs: Update custom-worker-script-location.mdx#507cdaringe wants to merge 1 commit intomswjs:mainfrom
Conversation
# problem I was getting errors and warnings despite setting the Service-Worker-Allowed header. # solution clarify that you MUST tell MSW about the scope!
|
@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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Got it! Would appreciate if you posted the original warning though. Makes it easier for people to discover this in hindsight. Thanks.
problem
I was getting errors and warnings despite setting the Service-Worker-Allowed header.
solution
clarify that you MUST tell MSW about the scope!