Skip to content

API Bug: backgroundLoaded event doesn't fire for environments #11

@robrab2000

Description

@robrab2000

API Bug: backgroundLoaded event doesn't fire for environments, only for backgrounds

Description

The backgroundLoaded event documentation states it should fire for both backgrounds and environments, but it only fires for backgrounds. Environment loading completion is not detected. According to the API Documentation, the backgroundLoaded event should fire when the background or an environment is loaded but it only seems to work for a background, not an environment. This even seems to happens in your own Sample Examples.

Expected Behavior

  • backgroundLoaded event should fire when any background content is loaded (environments, background images, background colors)
  • This would allow developers to track complete loading progress including all background assets

Actual Behavior

  • backgroundLoaded event only fires when manually changing background images
  • The event does not fire for environments at all, even when they're the primary background content
  • This makes it unreliable for tracking loading progress of environment-based backgrounds

Steps to Reproduce

  1. Load a model with an environment (not just a background image/color)
  2. Add event listener for backgroundLoaded:
    api.addEventListener('backgroundLoaded', () => {
        console.log('Background loaded!');
    });
  3. The event never fires, even though the environment is clearly loaded and visible
  4. Only fires when manually changing background images

Code Example

// This never fires for environments
api.addEventListener('backgroundLoaded', () => {
    console.log('Background loaded - this should fire for environments too');
});

// Test different background changes - only the image change triggers the event
api.setEnvironment('studio'); // No event fired
api.setBackgroundColor('#ff0000'); // No event fired  
api.setBackgroundImage('https://example.com/image.jpg'); // Event fires only after this change

This replaces the current code example section and shows that the event only fires when changing to a background image, not when setting environments or background colors.

Impact

This prevents developers from accurately tracking complete loading progress for models with environments, as the backgroundLoaded event cannot be relied upon for environment loading. Developers must use workarounds like waiting for viewerready to assume all background content is loaded.

Environment

  • Sketchfab Viewer API v1.12.1
  • Tested with models that have environments (not just background images)
  • Browser: Chrome/Firefox/Safari

Additional Context

The official documentation example shows the event being used, but doesn't clarify that it only fires for background images/colors, not for environments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions