Add fetch() polyfill over XMLHttpRequest for Playground#1707
Open
bkaradzic-microsoft wants to merge 1 commit into
Open
Add fetch() polyfill over XMLHttpRequest for Playground#1707bkaradzic-microsoft wants to merge 1 commit into
bkaradzic-microsoft wants to merge 1 commit into
Conversation
Implements a minimal `fetch(input, init)` polyfill in Apps/Playground that wraps XMLHttpRequest. Provides a Response-like result with `.ok`, `.status`, `.statusText`, `.url`, `.text()`, `.arrayBuffer()`, `.json()`, `.blob()`, and a `headers` stub. Self-detecting: no-op if a global `fetch` already exists; bails if XMLHttpRequest is unavailable. Wired into the Playground SCRIPTS list and loaded by AppContext before `ammo.js` / `babylon.max.js` so playground snippets that use the modern `fetch` API can run on Babylon Native's host environments (Chakra and V8), which do not provide `fetch` by default. Babylon Native's `XMLHttpRequest` only dispatches events through `addEventListener` (no `onload`/`onerror` properties) and fires `loadend` rather than `load`; the polyfill listens on `loadend` and inspects `status` to decide resolve/reject. When `responseType` is `arraybuffer`, BN's `XHR.responseText` is empty, so `.text()` decodes the array buffer directly rather than reading `responseText`.
This was referenced May 18, 2026
ryantrem
reviewed
May 18, 2026
Member
ryantrem
left a comment
There was a problem hiding this comment.
Similar question as the other PR - should we just add a full native fetch polyfill? Maybe we could add it to XMLHttpRequest (@bghgary might say no though 😅), or a new polyfill. It would be good to have this in BN anyway so the BJS codebase can use fetch rather than XMLHttpRequest.
bghgary
requested changes
May 21, 2026
Contributor
bghgary
left a comment
There was a problem hiding this comment.
[Reviewed by Copilot on behalf of @bghgary]
Same as #1700 and #1706 — fetch is a standard web API that Babylon.js code paths depend on. Should be a proper C++ polyfill under Polyfills/, not a Playground-only JS script. See BabylonJS/JsRuntimeHost#98.
bkaradzic-microsoft
added a commit
that referenced
this pull request
May 21, 2026
Per-test PIL-composite triage of all 17 ``subtle pixel-diff`` tests. None of them are deterministic-cosmetic (no re-bakes possible - all show real visible regressions). Updates the `reason` field in `Apps/Playground/Scripts/config.json` for 17 tests with accurate symptom descriptions, classifying into recurring root-cause clusters: - 9 GUI green->red color regressions (idx 160, 174, 175, 196, 197, 370, 402, 566, 587) - 4 OpenPBR analytic-lights right-column red rendering (580, 584, 587, 592) - 1 instanced billboard foliage red (169) - 1 LineEdgesRenderer extra red lines (179) - 1 Background blur red splotches (602) - 1 Clip planes GUI sliders red (182) - 1 Instanced Bones edge-AA (256, borderline) **No source changes, no test re-enables, no PNGs.** Metadata-only correction so the issue tracker reflects actionable root causes. --- ## Landing context This PR is one of **7 splits** from the proven CI-green combined preview in **draft PR #1702** (see [#1702](#1702) for the full intended end-state and verified CI run [26044922430](https://github.com/BabylonJS/BabylonNative/actions/runs/26044922430)). > Note: the original split included an 8th PR (#1709, ES2020+ -> ES2019 syntax-repair polyfill for Chakra). It was closed in favour of investigating `@babel/standalone` properly (#1711). ### Recommended landing order **Tier 1 - parallel-reviewable, no source conflicts:** 1. #1703 - ExternalTexture C4702 build fix 2. #1704 - config.json `reason` rewrites (5 entries) 3. #1705 - config.json `reason` rewrites (17 entries) **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` SCRIPTS list + `Apps/Playground/Shared/AppContext.cpp` LoadScript order; rebase the next branch after the previous merges:** 4. #1706 - File/Blob/FileReader polyfill (largest test impact: 19 re-enables) 5. #1707 - fetch polyfill 6. #1708 - DOM globals + native AbortController + Android CMake link 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**.
bkaradzic-microsoft
added a commit
that referenced
this pull request
May 21, 2026
Per-test triage of 5 post-#1695 pixel-diff fallouts. Updates the `reason` field in `Apps/Playground/Scripts/config.json` for 3 entries to name the real BN rendering regression instead of generic "Pixel comparison fails": - idx 363 SSR2 - SSR not rendering wet floor. - idx 369 Sprites Pixel Perfect - sprite alpha-blending broken. - idx 395 soft-transparent-shadows - soft-shadow filter precision degraded. **No source changes, no test re-enables, no PNGs.** Metadata-only correction so the issue tracker reflects actionable root causes for follow-up engineering work. --- ## Landing context This PR is one of **7 splits** from the proven CI-green combined preview in **draft PR #1702** (see [#1702](#1702) for the full intended end-state and verified CI run [26044922430](https://github.com/BabylonJS/BabylonNative/actions/runs/26044922430)). > Note: the original split included an 8th PR (#1709, ES2020+ -> ES2019 syntax-repair polyfill for Chakra). It was closed in favour of investigating `@babel/standalone` properly (#1711). ### Recommended landing order **Tier 1 - parallel-reviewable, no source conflicts:** 1. #1703 - ExternalTexture C4702 build fix 2. #1704 - config.json `reason` rewrites (5 entries) 3. #1705 - config.json `reason` rewrites (17 entries) **Tier 2 - sequential, each touches `Apps/Playground/CMakeLists.txt` SCRIPTS list + `Apps/Playground/Shared/AppContext.cpp` LoadScript order; rebase the next branch after the previous merges:** 4. #1706 - File/Blob/FileReader polyfill (largest test impact: 19 re-enables) 5. #1707 - fetch polyfill 6. #1708 - DOM globals + native AbortController + Android CMake link 7. #1710 - Cubemap auto-expand polyfill (loaded after babylon.max.js) ### Reference policy reminder Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: **0 PNGs**.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a JS polyfill for
fetchso playgrounds depending on it stop hittingReferenceError: 'fetch' is not defined.Changes:
Apps/Playground/Scripts/fetch_polyfill.js- fullfetch(input, init)wrappingXMLHttpRequestwithResponse-liketext()/arrayBuffer()/json()/blob(). Self-detecting (no-op if globalfetchalready exists). Tailored to BN's XHR which dispatches only viaaddEventListenerand firesloadend(noload). DecodesArrayBufferfor.text()whenresponseTypeisarraybuffer.Apps/Playground/CMakeLists.txt- addsfetch_polyfill.jsto SCRIPTS list.Apps/Playground/Shared/AppContext.cpp- loadsfetch_polyfill.jsbeforefile_polyfill.js.Note: Polyfill resolves the headline error but re-enables 0 tests. 5 affected playground tests still excluded - they hit secondary blockers (4 MSDF tests need
babylonjs-addons, idx 151 needsearcut). Tracked as follow-ups.Verified: regression sweep clean on idx 0/5/10/47/100/165/200.
Landing context
This PR is one of 7 splits from the proven CI-green combined preview in draft PR #1702 (see #1702 for the full intended end-state and verified CI run 26044922430).
Recommended landing order
Tier 1 - parallel-reviewable, no source conflicts:
reasonrewrites (5 entries)reasonrewrites (17 entries)Tier 2 - sequential, each touches
Apps/Playground/CMakeLists.txtSCRIPTS list +Apps/Playground/Shared/AppContext.cppLoadScript order; rebase the next branch after the previous merges:Reference policy reminder
Reference PNGs across all 7 PRs come from Babylon.js; never re-baked by BN. Combined diff: 0 PNGs.