Skip to content

Running FCM on IP stops Angular rendering #3672

Done

Description

@Sammaye

I need to sometimes run my app on IP for mobile testing etc, and this used to work fine in Angular 16 since firebase would just ignore IPs but now, since Angular 20, I get:

TypeError: Cannot read properties of undefined (reading 'addEventListener')

eventually failing with

FirebaseError: Messaging: This browser doesn't support the API's required to use the Firebase SDK. (messaging/unsupported-browser).

But not before it halts the whole app and stops it rendering.

This should just not do anything when it detect a none 127.0.0.1 IP as it did before, seems like there has been a regression bug somewhere.

Specifically the issue provider is:

provideMessaging(() => getMessaging()),

Activity

  1. changed the title [-]Running on IP stops Angular rendering[/-] [+]Running FCM on IP stops Angular rendering[/+] on Sep 30, 2025
  2. added
    comp: messaging
    type: bug
    version: current (v17+)
    on Nov 25, 2026
  3. modified the milestones: 22.0.0, 22.1.0 on Nov 25, 2026
  4. armando-navarro commented on Nov 27, 2026

    @armando-navarro
    Collaborator

    Hi @Sammaye, thanks for reporting this, and I'm sorry it went over a year without an answer.

    You were right that this is a regression. What I found:

    • A page opened over plain HTTP at an IP address is not a secure context, so the browser gives it no navigator.serviceWorker. localhost is treated as secure, which is why it works there.
    • Firebase's getMessaging() uses navigator.serviceWorker without checking for it, and that is the TypeError you saw.
    • Through AngularFire 18, Messaging was null in a browser like that. 19.0.0 removed that check (Drop isSupported injection, bump rxfire #3588), and since then injecting Messaging there throws and stops the app from starting.

    #3852 fixes it, and its merge closed this issue:

    • Messaging is null again in a browser with no service worker, so the app renders.
    • It will be released in AngularFire 22.0.0 (coming soon).
    • I'd normally point you at a canary build to try, but canary publishing is broken right now, so there isn't one with the fix yet.
    • When you do get the fix, check Messaging for null before calling onMessage or onRegistered, which throw when handed null.

    Until you're on AngularFire 22.0.0

    AngularFire 22.0.0 is for Angular 22, and you were on Angular 20, so here is something that works today. Ask Firebase's isSupported() first, and take Messaging from the injector only when the answer is yes:

    private readonly injector = inject(Injector);
    private messaging: Messaging | null = null;
    
    constructor() {
      isSupported().then(supported => {
        if (supported) {
          this.messaging = this.injector.get(Messaging);
        }
      });
    }

    isSupported and Messaging come from @angular/fire/messaging, and Injector and inject from @angular/core.

    I ran this on Angular 20 with @angular/fire 20.0.1 over a LAN IP address. The app rendered with a clean console, and on localhost it still got a Messaging instance.

    If it still misbehaves for you, with this or on 22.0.0 once it's out, let me know here and I'll look into it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp: messagingtype: bugversion: current (v17+)

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions