Skip to content

Conversation

@harshasiddartha
Copy link
Contributor

Description

Fixed incorrect HTML example in the Flutter Web documentation for Firebase Cloud Messaging service worker registration.

Problem

The documentation showed inline JavaScript inside a <script> tag with a src attribute:

<script src="flutter_bootstrap.js" async>
  if ('serviceWorker' in navigator) {
    // ...
  }
</script>

This is incorrect because browsers ignore inline JavaScript when a script tag has a src attribute, which prevents the service worker registration from running.

Solution

Separated the script tags as follows:

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

<script>
  if ('serviceWorker' in navigator) {
    window.addEventListener('load', function () {
      navigator.serviceWorker.register('firebase-messaging-sw.js', {
        scope: '/firebase-cloud-messaging-push-scope',
      });
    });
  }
</script>

Related Issue

Fixes #17837

Testing

  • ✅ Analyzed code with melos analyze-ci - all checks passed
  • ✅ Verified HTML syntax is correct
  • ✅ Confirmed the fix matches the issue description

Type of Change

  • Documentation fix

…r registration

Separated inline JavaScript from script tag with src attribute. Browsers ignore inline JavaScript when a script tag has a src attribute, which was preventing the service worker registration from running.

Fixes firebase#17837
@gemini-code-assist
Copy link

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@google-cla
Copy link

google-cla bot commented Nov 2, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@harshasiddartha
Copy link
Contributor Author

I've signed the Google CLA. The commit email [email protected] is configured correctly in git and is associated with my GitHub account.

Steps taken:

Clicking the "New Contributors: Update this check" link to refresh the CLA status.

This PR fixes the incorrect HTML example in the documentation where inline JavaScript was incorrectly placed inside a script tag with a src attribute, which browsers ignore.

@SelaseKay
Copy link
Contributor

Hi @harshasiddartha, thanks for the contribution. LGTM!

@SelaseKay SelaseKay changed the title fix(firebase_messaging): fix incorrect HTML example for service worker registration doc(firebase_messaging): fix incorrect HTML example for service worker registration Nov 4, 2025
@SelaseKay SelaseKay changed the title doc(firebase_messaging): fix incorrect HTML example for service worker registration docs(firebase_messaging): fix incorrect HTML example for service worker registration Nov 4, 2025
@SelaseKay SelaseKay merged commit 6c263de into firebase:main Nov 4, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[firebase_messaging] Incorrect HTML example for firebase-messaging-sw.js registration in Flutter Web documentation

4 participants