fix(loader): recognize file:// as absolute URL in GetURL() to support offline environments #7210
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.
fix(loader): recognize
file://as absolute inGetURL()Summary
Under the
file://protocol,Phaser.Loader.GetURL()does not treatfile://URLs as absolute. When abaseURLis set, itgets prepended to an already-absolute
file://path, producing double-prefixed URLs like:Important scope clarification: In my environment, all other assets load correctly under
file://+setBaseURL(...).The problem manifests specifically when Spine atlas-derived page images (the
.pnglisted inside the.atlas) are queued.Those page images sometimes end up with an absolute
file://infile.url, andGetURL()then prependsbaseURLagain.This PR adds
file://to the absolute-URL check soGetURL()returns the original URL and does not concatenatebaseURL.This keeps atlas page images consistent with all other file types that already behave correctly in the same environment.
Why this matters
In our setup we must run under
file://(no local HTTP server available) and we must usethis.load.setBaseURL(...)to keep asset resolution consistent across browsers. Without this patch, using both
file://+baseURLbreaks Spine atlas page PNGs,while other assets remain fine. With this patch, Phaser treats
file://just likehttp(s),blob:, anddata:.Changes
// src/loader/GetURL.js var GetURL = function (file, baseURL) { if (!file.url) { return false; } - if (file.url.match(/^(?:blob:|data:|capacitor:\/\/|http:\/\/|https:\/\/|\/\/)/)) + if (file.url.match(/^(?:blob:|data:|capacitor:\/\/|file:\/\/|http:\/\/|https:\/\/|\/\/)/)) { return file.url; } else { return baseURL + file.url; } };Results
file.urlfile.srcassets/bg.pnghttp://localhost/.../assets/bg.pngfile://(before)file:///Users/.../spineboy-pma.pngfile:///base/.../file:///Users/.../spineboy-pma.pngfile://(after)file:///Users/.../spineboy-pma.pngfile:///Users/.../spineboy-pma.pngfile://(baseline)assets/...file:///base/.../assets/...Notes
http(s),blob:,data:, orcapacitor://environments.GetURL(); no other loader behavior is changed.file://withsetBaseURL(...)required for consistent resolution.