Skip to content

[web] serviceWorkerVersion is not defined at _getNewServiceWorker #130212

@p-mazhnik

Description

@p-mazhnik

Is there an existing issue for this?

Steps to reproduce

  1. Create a new web project with flutter create.
  2. Remove var serviceWorkerVersion = null; from the index.html
  3. provide custom service worker version to the loadEntrypoint (index.html):
_flutter.loader.loadEntrypoint({
        serviceWorker: {
          serviceWorkerVersion: '123',
        },
  1. Launch web app
  2. See Installing/Activating first service worker. message in the Chrome console (Verbose level)
  3. Refresh the page

Expected results

Message Loading from existing service worker. in the console, service worker is loaded.

Actual results

Service worker is not loaded with an exception in the console:

Exception while loading service worker: ReferenceError: serviceWorkerVersion is not defined
    at _getNewServiceWorker (flutter.js:175:49)

Code sample

Code sample
window.addEventListener('load', function(ev) {
      // Download main.dart.js
      _flutter.loader.loadEntrypoint({
        serviceWorker: {
          serviceWorkerVersion: '123',
        },
        onEntrypointLoaded: function(engineInitializer) {
          engineInitializer.initializeEngine().then(function(appRunner) {
            appRunner.runApp();
          });
        }
      });
    });

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.3.1 22E772610a darwin-arm64,
    locale ru-RU)
    • Flutter version 3.10.5 on channel stable at /Users/mazhnik/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (4 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/mazhnik/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • ANDROID_HOME = /Users/mazhnik/Library/Android/sdk
    • Java binary at: /Users/mazhnik/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841
      /Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Users/mazhnik/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841
      /Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.3)
    • IntelliJ at /Users/mazhnik/Applications/JetBrains Toolbox/IntelliJ IDEA
      Ultimate.app
    • Flutter plugin version 74.0.4
    • Dart plugin version 231.9161.14

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.3)
    • IntelliJ at /Users/mazhnik/Library/Application
      Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.9161.38/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.73.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • iPhone PM (mobile) • 00008120-000E511C14DB401E • ios            • iOS 16.0
      20A357
    • macOS (desktop)    • macos                     • darwin-arm64   • macOS
      13.3.1 22E772610a darwin-arm64
    • Chrome (web)       • chrome                    • web-javascript • Google
      Chrome 114.0.5735.198
    ! Error: iPhone PM is busy: Loading metadata for the watch via iPhone PM.
      Xcode will continue when iPhone PM is finished. (code -10)
    ! Error: (null) needs to connect to determine its availability. Check the
      connection between the device and its companion iPhone, and the connection
      between the iPhone and Xcode. Both devices may also need to be restarted
      and unlocked. (code 1)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listassigned for triageissue is assigned to a domain expert for further triagee: flutter.jsIssues with Flutter web custom initialization through JS APIsfound in release: 3.10Found to occur in 3.10found in release: 3.12Found to occur in 3.12has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-webOwned by Web platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions