Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception while loading service worker: Error: prepareServiceWorker took more than 4000ms to resolve. #147302

Closed
ammushajan opened this issue Apr 24, 2024 · 6 comments
Labels
in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds

Comments

@ammushajan
Copy link

ammushajan commented Apr 24, 2024

### Steps to reproduce

This happens on the initial page load on flutter web.

Code Sample

<!DOCTYPE html>
<html>
<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    This is a placeholder for base href that will be replaced by the value of
    the `--base-href` argument provided to `flutter build`.
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <link rel="stylesheet" href="styles.css" />

  <script defer>
    window.flutterfire_ignore_scripts = ['analytics', 'firestore'];
  </script>
  <script>
    // The value below is injected by flutter build, do not touch.
    const serviceWorkerVersion = null;
  </script>
  <!-- This script adds the flutter initialization JS code -->
  <script src="flutter.js" defer></script>
</head>
<body>
<script>
    window.addEventListener('load', function(ev) {
      // Download main.dart.js
      _flutter.loader.loadEntrypoint({
        serviceWorker: {
          serviceWorkerVersion: serviceWorkerVersion,
        },
        onEntrypointLoaded: function(engineInitializer) {
          engineInitializer.initializeEngine().then(function (appRunner) {
            appRunner.runApp();
          });
        }
      });
    });
</script>
<script>
  if ('serviceWorker' in navigator) {
    window.addEventListener('flutter-first-frame', function () {
      navigator.serviceWorker.register('./firebase-messaging-sw.js');
      const channel = new BroadcastChannel('bg-message');
      channel.addEventListener("message", function (event) {
        // post the message in window in order to get the notifciations
        window.postMessage(JSON.stringify(event.data.data))
      })
    });
  }
</script>
</body>
</style>
</html>

What target platforms are you seeing this bug on?

Web

OS/Browser name and version | Device information

Google Chrome
Version 124.0.6367.61 (Official Build) (arm64)

Does the problem occur on emulator/simulator as well as on physical devices?

No

Logs

No response

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.3 23D56 darwin-arm64, locale
    en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.88.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!
@ammushajan ammushajan added the from: performance template Issues created via a performance issue template label Apr 24, 2024
@As90909w

This comment was marked as off-topic.

@darshankawar darshankawar added in triage Presently being triaged by the triage team and removed from: performance template Issues created via a performance issue template labels Apr 25, 2024
@darshankawar
Copy link
Member

darshankawar commented Apr 25, 2024

@ammushajan
Please provide us reproducible code sample and entire error log in properly formatted text so that we can address it properly. Also check if this resembles your case or not.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 25, 2024
@ammushajan
Copy link
Author

@ammushajan Please provide us reproducible code sample and entire error log in properly formatted text so that we can address it properly. Also check if this resembles your case or not.
I've made some updates to the code. However, the issue I'm encountering is different from what you mentioned. For me, the main.dart file is taking a long time to load after deployment.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 25, 2024
@darshankawar
Copy link
Member

@ammushajan
I tried locally for which I am getting below error:

DOMException: Failed to register a ServiceWorker for scope ('http://localhost:50424/') with script ('http://localhost:50424/firebase-messaging-sw.js'): The script has an
unsupported MIME type ('text/html').

Can you provide complete error log ?
Also, does it throw same error when run locally in release mode ? or only after deploying ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 26, 2024
Copy link

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
Thanks for your contribution.

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds
Projects
None yet
Development

No branches or pull requests

3 participants