Skip to content

[πŸ“š] [firebase_messaging_web] How to load on Flutter 3.22?Β #12798

Closed
@stx

Description

@stx

https://firebase.google.com/docs/cloud-messaging/flutter/receive#web has this:

<html>
<body>
  ...
  <script src="main.dart.js" type="application/javascript"></script>
  <script>
       if ('serviceWorker' in navigator) {
          // Service workers are supported. Use them.
          window.addEventListener('load', function () {
            // ADD THIS LINE
            navigator.serviceWorker.register('/firebase-messaging-sw.js');

            // Wait for registration to finish before dropping the <script> tag.
            // Otherwise, the browser will load the script multiple times,
            // potentially different versions.
            var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;

            //  ...
          });
      }
  </script>

But the Flutter 3.22 index.html format is completely different:

<script src="flutter_bootstrap.js" async></script>

When using existing code in the example and other repos, these deprecations are thrown:

Warning: In index.html:30: Local variable for "serviceWorkerVersion" is deprecated. Use "{{flutter_service_worker_version}}" template token instead.
Warning: In index.html:243: "FlutterLoader.loadEntrypoint" is deprecated. Use "FlutterLoader.load" instead.

Can we get a complete example of loading this with Flutter 3.22?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions