Skip to content

LoaderPlugin XHR timeout is not handled #6472

@343dev

Description

@343dev

Version

  • Phaser Version: 3.55.2
  • Operating system: macOS
  • Browser: any

Description

Hey there!

I’ve noticed that LoaderPlugin doesn’t handle errors related to XHR timeout. If one of the requests times out in the preload state, the scene never transitions from the preload state to the create state.

How should we handle such errors in this case?

Example Test Code

Demo: https://codepen.io/343dev/pen/VwEaYLQ

class GameScene extends Phaser.Scene {
  constructor() {
    super('Game');
  }

  preload() {
    this.load.image('test', 'https://slowfil.es/file?type=png&delay=6000', { timeout: 1000, responseType: 'blob' });
  }

  create() {
    this.add.text(0,0,'loaded', { color: 'red' });
  }
}

const config = {
  transparent: true,
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  scene: [GameScene],
};

const game = new Phaser.Game(config);

Additional Information

  1. LoaderPlugin passes the mentioned parameters (responseType and timeout) to File: loader/filetypes/ImageFile.js#L70.
  2. File then uses these parameters to initiate an XHRLoader internally: loader/File.js#L297.
  3. And XHRLoader opens a connection with the specified timeout: loader/XHRLoader.js#L31.
  4. If a timeout occurs, the timeout event is triggered in XHR: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout_event.
  5. However, there seems to be no handling of this event in XHRLoader: loader/XHRLoader.js#L63-L65.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions