Skip to content

[Bug] Prevent unhandled fetch failures in service workerΒ #5964

@DhyaniKavya

Description

@DhyaniKavya

Description:-
-The Service Worker attempts to update cached responses in the background using fetch(event.request) inside event.waitUntil(). When the user is offline or the network request fails, this fetch promise rejects without a .catch() handler.
-This results in an Uncaught (in promise) TypeError: Failed to fetch error in the Service Worker context. Although the cached response or offline fallback is still served, the unhandled rejection introduces runtime errors and reduces reliability.
-Proper promise handling is required to ensure safe offline operation and error-free background cache updates.

Expected Behavior:-
-Background cache update requests should fail gracefully when offline.
-No unhandled promise rejections should occur in the Service Worker.
-Cached responses or offline fallback content should continue to be served normally.
-Network failures should be safely ignored where appropriate.

How to Reproduce:-
-Open Music Blocks in a browser.
-Ensure the Service Worker is active.
-Load a page/resource so it is cached.
-Turn off internet connectivity.
-Refresh or navigate to trigger a cached response.
-Observe the browser console.
-You may see:
->Uncaught (in promise) TypeError: Failed to fetch
-Console log Errors:
->Uncaught (in promise) TypeError: Failed to fetch
->Occurs when offline and background fetch fails.

Environment:
-Operating System: Windows / macOS / Linux
-Browser: Chrome / Firefox / Edge / Safari
-Version of Software/Project: Latest (master branch)

Impact:
-Medium
-Generates unnecessary runtime errors in offline scenarios
-Reduces Service Worker reliability
-May affect debugging and error monitoring

Suggested Fix:
-Add a safe .catch() handler to the background fetch inside event.waitUntil():

=>fetch(event.request)
.then(...)
.catch(() => {
// ignore offline failures
});

Checklist

  • I have read and followed the project's code of conduct.
  • I have searched for similar issues before creating this one.
  • I have provided all the necessary information to understand and reproduce the issue.
  • I am willing to contribute to the resolution of this issue.

Thank you for contributing to our project! We appreciate your help in improving it.

πŸ“š See contributing instructions.

πŸ™‹πŸΎπŸ™‹πŸΌ Questions: Community Matrix Server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions