Skip to content

Conversation

@aomsir
Copy link

@aomsir aomsir commented Oct 26, 2025

fix(loader): recognize file:// as absolute in GetURL()

Summary

Under the file:// protocol, Phaser.Loader.GetURL() does not treat file:// URLs as absolute. When a baseURL is set, it
gets prepended to an already-absolute file:// path, producing double-prefixed URLs like:

file:///Users/.../spine--demo.../file:///Users/.../assets/spine/spineboy-pma.png

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 .png listed inside the .atlas) are queued.
Those page images sometimes end up with an absolute file:// in file.url, and GetURL() then prepends baseURL again.

This PR adds file:// to the absolute-URL check so GetURL() returns the original URL and does not concatenate baseURL.
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 use this.load.setBaseURL(...)
to keep asset resolution consistent across browsers. Without this patch, using both file:// + baseURL breaks Spine atlas page PNGs,
while other assets remain fine. With this patch, Phaser treats file:// just like http(s), blob:, and data:.


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

Environment Case file.url file.src Outcome
HTTP / HTTPS any asset assets/bg.png http://localhost/.../assets/bg.png ✅ OK
file:// (before) Spine atlas page PNG (derived file) file:///Users/.../spineboy-pma.png file:///base/.../file:///Users/.../spineboy-pma.png ❌ BAD
file:// (after) Spine atlas page PNG (derived file) file:///Users/.../spineboy-pma.png file:///Users/.../spineboy-pma.png ✅ OK
file:// (baseline) regular images / audio / json assets/... file:///base/.../assets/... ✅ OK

Notes

  • No impact on http(s), blob:, data:, or capacitor:// environments.
  • Patch is isolated to GetURL(); no other loader behavior is changed.
  • Verified on Phaser 3.90.0 (macOS + Chrome) under file:// with setBaseURL(...) required for consistent resolution.

@aomsir
Copy link
Author

aomsir commented Oct 26, 2025

Additional context

I have reviewed issue #6642 and confirmed that it partially addresses the baseURL + absolute path duplication issue for HTTP/HTTPS cases.

However, the file:// protocol is still affected.
Even with the fix from #6642 (file.srcfile.url), when running under file:// with a baseURL set, the loader still prepends baseURL to already-absolute file:// URLs—most notably for Spine atlas page PNGs.
This patch extends the absolute URL detection in GetURL() to include file://, ensuring parity between file:// and other absolute schemes such as http(s):, blob:, and data:.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant