Skip to content

Log a failing initial background image instead of rejecting unhandled - #148

Merged
changt merged 1 commit into
mainfrom
catch-initial-background-load
Oct 22, 2026
Merged

changt merged 1 commit into
mainfrom
catch-initial-background-load

Conversation

@changt

@changt changt commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #141.

What

BackgroundTransformer's constructor calls the async update() without awaiting it. If the initial imagePath failed to load (404, CORS, aborted request), the rejection had no handler. It reached the page as an unhandled promise rejection with no message (the value is a DOM Event), and callers had no way to catch it.

The constructor now attaches a .catch() that logs the failure, matching how init() already handles the same load.

Why not move the load into init()

The issue suggests that as the preferred fix. I kept the constructor preload because apps often construct the processor well before setProcessor() (on a pre-join screen, for example), and the preload lets init() reuse the already-decoded image. Functionally nothing changes:

  • On failure, init() still retries the load and logs.
  • On success, init() still skips the fetch because the image is already cached.

Test

Adds e2e case D6: the harness constructs the processor with a background image that returns 404, then the test asserts no pageerror and no harness error. It also checks the image was actually requested, so it can't pass trivially. With the fix reverted, D6 fails with an uncaught page error "Event".

Includes a patch changeset.

The constructor called the async update() without awaiting or catching it,
so an imagePath that failed to load surfaced as an unhandled promise
rejection that callers had no way to handle. It is now caught and logged,
matching how init() handles the same failure.

Adds e2e case D6, which constructs the processor with a 404ing image and
asserts the page reports no uncaught error.

Fixes #141
@changeset-bot

changeset-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e6005dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@livekit/track-processors Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines 64 to 67
const fileSet = await vision.FilesetResolver.forVisionTasks(
this.options.assetPaths?.tasksVisionFileSet ??
`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${dependencies['@mediapipe/tasks-vision']}/wasm`,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: would it also make sense to fetch fileSet in the constructor as well for a similar reason (frontloading a potentially large request?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But will do in a separate PR.

@changt
changt merged commit c93818a into main Oct 22, 2026
3 checks passed
@changt
changt deleted the catch-initial-background-load branch October 22, 2026 16:34
@github-actions github-actions Bot mentioned this pull request Oct 22, 2026
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.

BackgroundTransformer's constructor does not await update(), so a failing imagePath is an unhandled rejection (and is fetched twice)

2 participants