Skip to content

Commit c05b1cd

Browse files
idethymikee
authored andcommitted
fix: Ensure that bundle URL origin matches debugger page origin (#403)
This structurally sets up the Chrome debugger not to have CORS issues if the bundle URL domain differs from the Chrome debugger page domain. This bug was initially fixed in facebook/react-native#17720 and regressed in #194. This commit fixes the original bug without changing the behavior introduced in #194. This commit makes the debugger page use its own URL origin when loading the bundle URL. This addresses the case where the native client may have a bundle URL with a domain like xip.io. Fundamentally, unless the development server allows cross-origin requests, the bundle URL's domain must match the domain used by the Chrome debugger page, which is what this commit achieves.
1 parent 678510f commit c05b1cd

File tree

1 file changed

+9
-1
lines changed
  • packages/cli/src/commands/server/debugger-ui

1 file changed

+9
-1
lines changed

packages/cli/src/commands/server/debugger-ui/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,15 @@
219219
connectToDebuggerProxy();
220220

221221
async function getBlobUrl(url) {
222-
return await window.deltaUrlToBlobUrl(url.replace('.bundle', '.delta'));
222+
// Ensure that the bundle URL has the same origin as this webpage so that
223+
// the same-origin policy lets us fetch it
224+
const urlObject = new URL(url, location);
225+
const relativeUrl = urlObject.pathname.replace('.bundle', '.delta') +
226+
urlObject.search +
227+
urlObject.hash;
228+
const localUrl = new URL(relativeUrl, location).toString();
229+
230+
return await window.deltaUrlToBlobUrl(localUrl);
223231
}
224232
})();
225233
</script>

0 commit comments

Comments
 (0)