msw icon indicating copy to clipboard operation
msw copied to clipboard

Use "document.baseURI" as the relative request's base URL

Open kettanaito opened this issue 5 years ago • 4 comments

Current behavior

We use location.origin to be the base URL for relative requests.

https://github.com/mswjs/msw/blob/445fc63f9447df2df346c64d1a751d43b284e52a/src/utils/url/getAbsoluteUrl.ts#L10-L12

While this works, certain scenarios won't have a location set (i.e. sandboxed iframes). Relative request URL resolution would fail in those cases.

Expected behavior

Use document.baseURI instead, which is always set on the document.

kettanaito avatar Nov 26 '21 12:11 kettanaito

I would like to jump on this and would open a PR soon.

watife avatar Nov 27 '21 11:11 watife

@watife, that'd be incredible! Feel free to open the pull request, I'd be glad to help you with the code review and making this improvement happen. Let's improve the experience for developers together.

kettanaito avatar Nov 27 '21 11:11 kettanaito

@watife @kettanaito Is this baseUrl option documented somewhere?

athrunsun avatar Dec 02 '21 03:12 athrunsun

Hey, @athrunsun. There's no baseUrl option supported in MSW. That's an intentional decision and you can learn more about it here.

This particular change has updated an internal implementation detail to result in more reliable relative requests matching in various contexts. This is not a public, developer-facing API.

kettanaito avatar Dec 02 '21 09:12 kettanaito