♻️ use global URL constructor and fall back to pristine iframe only when needed - #4967
♻️ use global URL constructor and fall back to pristine iframe only when needed#4967BenoitZugmeyer wants to merge 2 commits into
Conversation
|
Bundles Sizes Evolution
|
43504fc to
86cdaa1
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86cdaa17ca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } catch { | ||
| // ignore | ||
| } | ||
| return getPristineWindow().URL |
There was a problem hiding this comment.
Keep the fallback safe inside Shopify pixels
issue: When this probe rejects the global constructor in a Shopify Custom Pixel, getPristineWindow() reads URL from the nested iframe's cross-origin contentWindow; that property access is outside its try block and throws a SecurityError. This commit simultaneously removes the contentWindow shim that previously prevented that access, so the advertised fallback breaks view/URL resolution precisely when a patched or partially functional URL makes it necessary. Keep the Shopify guard or make the pristine-constructor lookup safely fall back without accessing the cross-origin window.
AGENTS.md reference: packages/js-core/AGENTS.md:L33-L44
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
No, the URL should be available in shopify pixel environment, so we won't need this fallback.
86cdaa1 to
f1637bd
Compare
…hen needed Creating a hidden iframe on every page just to read an unpatched URL constructor is wasteful when the global one works fine. Probe it with a relative-URL resolution check and only fall back to the iframe-sourced constructor when it is patched or broken. This also drops the contentWindow shim in the Shopify sandbox patch, no longer needed now that the iframe path is not taken by default.
f1637bd to
0c09ad8
Compare
Motivation
The SDK creates a hidden
<iframe>on every page just to read an unpatchedURLconstructor, even though the globalURLworks correctly in the vast majority of environments. This is wasteful and can interfere with strict sandboxed contexts (e.g. Shopify Custom Pixels). We should only fall back to the iframe when the global constructor is actually patched or broken.Changes
buildUrlnow probes the globalURLconstructor with a relative-URL resolution check and uses it directly when it behaves correctly, falling back to the pristine iframe-sourced constructor only when needed.HTMLIFrameElement.prototype.contentWindowshim from the Shopify sandbox patch, no longer necessary now that the iframe path is not taken by default.urlPolyfill.spec.tsnext to its source file injs-core.Test instructions
window.URLwith a throwing function in the console, then trigger a navigation: URLs should still resolve via the iframe fallback.Checklist