Skip to content

Service Worker: registration.pushManager can be undefined in some mobile browser #25781

Closed

Description

@leo6104

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  

Current behavior

I start to use service-worker SwPush feature for webpush but some mobile browser throw Cannot read property 'getSubscription' of undefined error message.

Error Message

TypeError: Cannot read property 'getSubscription' of undefined
  at project(.../node_modules/@angular/service-worker/fesm5/service-worker.js.pre-build-optimizer.js:131:99)
  at _next(.../node_modules/rxjs/_esm5/internal/operators/switchMap.js.pre-build-optimizer.js:34:27)
  at next(.../node_modules/rxjs/_esm5/internal/Subscriber.js.pre-build-optimizer.js:54:18)
  at _next(.../node_modules/rxjs/_esm5/internal/operators/map.js.pre-build-optimizer.js:41:26)
  at next(.../node_modules/rxjs/_esm5/internal/Subscriber.js.pre-build-optimizer.js:54:18)
  at notifyNext(.../node_modules/rxjs/_esm5/internal/operators/switchMap.js.pre-build-optimizer.js:66:26)
  at _next(.../node_modules/rxjs/_esm5/internal/InnerSubscriber.js.pre-build-optimizer.js:15:21)
  at next(.../node_modules/rxjs/_esm5/internal/Subscriber.js.pre-build-optimizer.js:54:18)
  at apply(.../node_modules/rxjs/_esm5/internal/util/subscribeToPromise.js.pre-build-optimizer.js:7:28)
  at invoke(.../node_modules/zone.js/dist/zone.js.pre-build-optimizer.js:388:26)
  at run(.../node_modules/zone.js/dist/zone.js.pre-build-optimizer.js:138:43)
  at apply(.../node_modules/zone.js/dist/zone.js.pre-build-optimizer.js:872:34)
  at invokeTask(.../node_modules/zone.js/dist/zone.js.pre-build-optimizer.js:421:31)
  at runTask(.../node_modules/zone.js/dist/zone.js.pre-build-optimizer.js:188:47)
  at drainMicroTaskQueue(.../node_modules/zone.js/dist/zone.js.pre-build-optimizer.js:595:35)

Expected behavior

No error message if PushManager is undefined.

Minimal reproduction of the problem with instructions

These two line is problem. registration.pushManager can be undefined.
https://github.com/angular/angular/blob/master/packages/service-worker/src/push.ts#L39
https://github.com/angular/angular/blob/master/packages/service-worker/src/push.ts#L42

What is the motivation / use case for changing the behavior?

I just use SwPush in service-worker

Environment

some of Android 8.0 ~ 5.0.2 Chrome / Facebook browser throw the error.
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/pushManager#Browser_compatibility


Angular version: 6.1.4


Browser:
- [x] Chrome (Android) version 67.0.3 ~ 68.0.3
- [x] Facebook (Android) version 187 

Activity

  1. added this to the needsTriage milestone on Sep 4, 2018
  2. gkalpak commented on Sep 5, 2018

    @gkalpak
    Member

    Interesting 🤔
    It would be nice if we knew exactly what browser/version fails. From what I can tell, it should be supported in all major browsers (except for IE).

  3. leo6104 commented on Sep 5, 2018

    @leo6104
    ContributorAuthor

    @gkalpak In my service, 2.3k users cannot access to the service because of this issue.

    Here is Sentry log (Browser statistic of this error)
    53.57% | Chrome Mobile 68.0.3440 | 5 minutes ago
    15.43% | Facebook 186.0.0 | 6 days ago
    8.70% | Facebook 187.0.0 | a few seconds ago
    6.84% | Facebook 185.0.0 | 28 minutes ago
    3.99% | Chrome Mobile 66.0.3359 | 17 minutes ago
    1.91% | Facebook 184.0.0 | 2 days ago
    1.86% | Chrome Mobile 67.0.3396 | 5 hours ago
    1.74% | Chrome Mobile 65.0.3325 | 26 minutes ago
    0.92% | Chrome Mobile 20.0.0 | a day ago
    0.87% | Facebook 181.0.0 | 39 minutes ago
    0.46% | Chrome Mobile 44.0.2403 | 16 hours ago
    0.39% | Facebook 179.0.0 | 4 days ago
    0.36% | Facebook 180.0.0 | 3 hours ago

    Chrome Mobile and Facebook latest version still have this issue. (But it seems not for always but specific condition make this error) I was trying to find the condition but not found yet.. 🤔

  4. leo6104 commented on Sep 5, 2018

    @leo6104
    ContributorAuthor

    Ionic PWA tools also faced this issue in their pwa project and resolved the issue.
    ionic-team/ionic-pwa-toolkit#4

  5. leo6104 commented on Sep 5, 2018

    @leo6104
    ContributorAuthor

    As gkalpak said in my PR, it seems if i handle this error in this.swPush.subscription.subscribe second argument, it could be handle with catching error. So i close this issue.

  6. gkalpak commented on Sep 5, 2018

    @gkalpak
    Member

    Thx for the detailed info. The fact that it happens some of the time sounds like a browser bug (since there is nothing in the spec indicating that pushManager could be undefined).

    The ionic issue seems to be different, since there the registration itself is undefined (while here, registration is defined, but registration.pushManager is not 🤷‍♂️).

  7. gkalpak commented on Sep 5, 2018

    @gkalpak
    Member

    BTW, I would be curious to know whether window.PushManager is defined when the error happens.

  8. Serginho commented on Mar 11, 2019

    @Serginho
    Contributor

    @gkalpak I can confirm this is happening, at least, in the following browsers.

    Chrome WebView (70.0.3538.80) running over Android (7.0)
    Chrome (72.0.3626.121) running over Android (8.1.0)
    Facebook (211.0.0.43.112) running over Android (6.0.1)
    Android Browser (4.0) running over Android (7.0)

    Is this reported to Chromium team?

    The interesting thing is we never subscribe to SwPush.subscription, we always use SwPush.requestSubscription, but this lines is executing...

    const workerDrivenSubscriptions = this.pushManager.pipe(switchMap(pm => pm.getSubscription()));

  9. gkalpak commented on Mar 12, 2019

    @gkalpak
    Member

    Is this reported to Chromium team?

    Not to my knowledge. If you have enough info, please report it (and post a link to the issue here).

    The interesting thing is we never subscribe to SwPush.subscription, we always use SwPush.requestSubscription, but this lines is executing...

    Are you using SwPush#unsubscribe()? If not, then that line should not be executed indeed. Happy to look into it, if you can provide a minimal reproduction.

  10. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  11. locked and limited conversation to collaborators on Sep 14, 2019
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

    area: service-workerIssues related to the @angular/service-worker package

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions