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

[web] serviceWorkerVersion is not defined at _getNewServiceWorker #130212

Closed
2 tasks done
p-mazhnik opened this issue Jul 8, 2023 · 11 comments · Fixed by #131240
Closed
2 tasks done

[web] serviceWorkerVersion is not defined at _getNewServiceWorker #130212

p-mazhnik opened this issue Jul 8, 2023 · 11 comments · Fixed by #131240
Assignees
Labels
assigned for triage issue is assigned to a domain expert for further triage e: flutter.js Issues with Flutter web custom initialization through JS APIs found in release: 3.10 Found to occur in 3.10 found in release: 3.12 Found to occur in 3.12 has reproducible steps The issue has been confirmed reproducible and is ready to work on P1 High-priority issues at the top of the work list platform-web Web applications specifically r: fixed Issue is closed as already fixed in a newer version team-web Owned by Web platform team

Comments

@p-mazhnik
Copy link
Contributor

p-mazhnik commented Jul 8, 2023

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!
@Snowden1996
Copy link

The error is that the serviceWorkerVersion property is not defined. This can be fixed by adding the following line to the loadEntrypoint function:

serviceWorkerVersion: '1',

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Jul 10, 2023
@darshankawar
Copy link
Member

Thanks for the report and potential fix @p-mazhnik, but I am unable to replicate the error you provided upon running the updated index.html code snippet using latest stable and master versions. I also checked the Chrome's browser console wherein I didn't get the specified error.

Are there any missing steps to replicate it properly ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 10, 2023
@p-mazhnik
Copy link
Contributor Author

@darshankawar hi, here is my web/index.html file in case steps are not clear (attaching as a txt file to bypass GitHub's rule): index.txt

@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 Jul 10, 2023
@p-mazhnik
Copy link
Contributor Author

p-mazhnik commented Jul 10, 2023

Attaching video as well.

video

@darshankawar
Copy link
Member

Thanks for the details. I was able to replicate the error as posted. The error is triggered upon tapping the refresh button from the browser instance and not using the tool (hot restart).

stable, master flutter doctor -v
[!] Flutter (Channel stable, 3.10.5, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.10.5 on channel stable at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (2 days ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

[!] Flutter (Channel master, 3.12.0-15.0.pre.82, on macOS 12.2.1 21D62
    darwin-x64, locale en-GB)
    • Flutter version 3.12.0-15.0.pre.82 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ad74a4f76c (65 minutes ago), 2023-07-10 23:51:23 -0400
    • Engine revision 312e4813a8
    • Dart version 3.1.0 (build 3.1.0-292.0.dev)
    • DevTools version 2.25.0
    • If those were intentional, you can disregard the above warnings; however
      it is recommended to use "git" directly to perform update checks and
      upgrades.


[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/dhs/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for
      more details.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 13C100
    • CocoaPods version 1.11.2

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

[✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 65.1.4
    • Dart plugin version 213.7228

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

[✓] Connected device (3 available)
    • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
      • iOS 15.3.1 19D52
    • macOS (desktop)           • macos                                    •
      darwin-x64     • macOS 12.2.1 21D62 darwin-x64
    • Chrome (web)              • chrome                                   •
      web-javascript • Google Chrome 109.0.5414.119

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

! Doctor found issues in 1 category.
      
[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.



@darshankawar darshankawar added platform-web Web applications specifically has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.10 Found to occur in 3.10 found in release: 3.12 Found to occur in 3.12 team-web Owned by Web platform team and removed in triage Presently being triaged by the triage team labels Jul 11, 2023
@yjbanov yjbanov added will need additional triage This issue or PR needs attention before being routed to secondary triage assigned for triage issue is assigned to a domain expert for further triage labels Jul 13, 2023
@ditman
Copy link
Member

ditman commented Jul 13, 2023

"serviceWorkerVersion is not defined"
...
2. Remove var serviceWorkerVersion = null; from the index.html

@p-mazhnik please, don't do this. There's even a "do not touch the following line" in the index.html warning against doing this :) The current flutter build web command replaces the value of serviceWorkerVersion by a build number, if it's in your index.html.

The current approach might change when something like this happens:

But for now, if you remove serviceWorkerVersion, the build system will never add it back.

Can you try not deleting it from your index.html, and seeing if the "not defined" error goes away?

@ditman ditman added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 13, 2023
@p-mazhnik
Copy link
Contributor Author

@ditman
Well, main issue here is that flutter.js is trying to read serviceWorkerVersion from the global context, instead of the one provided to the loadEntrypoint function.

The only reason I added Remove var serviceWorkerVersion = null; step, is because it is an easy way to prove that flutter.js is not using provided serviceWorkerVersion.

Also, it is now possible to embed Flutter into existing web app without iframe (thanks for that), so index.html won't be used at all, but we can't provide serviceWorkerVersion to the flutter.js because of this issue.

@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 Jul 13, 2023
@ditman
Copy link
Member

ditman commented Jul 13, 2023

You're absolutely right! Let's fix the _getNewServiceWorker call to pass in the version :/

@ditman ditman added the P1 High-priority issues at the top of the work list label Jul 13, 2023
@p-mazhnik
Copy link
Contributor Author

I have a small PR with tests that fixes it: #130206

@ditman ditman added the e: flutter.js Issues with Flutter web custom initialization through JS APIs label Jul 13, 2023
@ditman
Copy link
Member

ditman commented Jul 13, 2023

Thanks @p-mazhnik! Let's get it landed!

@yjbanov yjbanov removed the will need additional triage This issue or PR needs attention before being routed to secondary triage label Jul 18, 2023
auto-submit bot pushed a commit that referenced this issue Sep 14, 2023
#131240)

Fixes #130212

Fix `Unresolved variable or type 'serviceWorkerVersion'` in the `_getNewServiceWorker` function.  

Supersedes #130206
@darshankawar darshankawar added the r: fixed Issue is closed as already fixed in a newer version label Sep 19, 2023
@github-actions
Copy link

github-actions bot commented Oct 3, 2023

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 Oct 3, 2023
Mairramer pushed a commit to Mairramer/flutter that referenced this issue Oct 10, 2023
flutter#131240)

Fixes flutter#130212

Fix `Unresolved variable or type 'serviceWorkerVersion'` in the `_getNewServiceWorker` function.  

Supersedes flutter#130206
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
assigned for triage issue is assigned to a domain expert for further triage e: flutter.js Issues with Flutter web custom initialization through JS APIs found in release: 3.10 Found to occur in 3.10 found in release: 3.12 Found to occur in 3.12 has reproducible steps The issue has been confirmed reproducible and is ready to work on P1 High-priority issues at the top of the work list platform-web Web applications specifically r: fixed Issue is closed as already fixed in a newer version team-web Owned by Web platform team
Projects
None yet
5 participants