Skip to content

Commit 9ba1f05

Browse files
committed
Removed customizable timeout
1 parent e2ee513 commit 9ba1f05

File tree

10 files changed

+11
-46
lines changed

10 files changed

+11
-46
lines changed

.changeset/neat-beans-rescue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
'@firebase/messaging': minor
2+
'@firebase/messaging': patch
33
---
44

55
Fix an issue where PushManager.subscribe() is called too soon after registering the default service worker.

common/api-review/messaging-sw.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export function getMessaging(app?: FirebaseApp): Messaging;
2424
// @public
2525
export interface GetTokenOptions {
2626
serviceWorkerRegistration?: ServiceWorkerRegistration;
27-
serviceWorkerRegistrationTimeout?: number;
2827
vapidKey?: string;
2928
}
3029

common/api-review/messaging.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export function getToken(messaging: Messaging, options?: GetTokenOptions): Promi
2727
// @public
2828
export interface GetTokenOptions {
2929
serviceWorkerRegistration?: ServiceWorkerRegistration;
30-
serviceWorkerRegistrationTimeout?: number;
3130
vapidKey?: string;
3231
}
3332

docs-devsite/messaging_.gettokenoptions.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export interface GetTokenOptions
2323
| Property | Type | Description |
2424
| --- | --- | --- |
2525
| [serviceWorkerRegistration](./messaging_.gettokenoptions.md#gettokenoptionsserviceworkerregistration) | ServiceWorkerRegistration | The service worker registration for receiving push messaging. If the registration is not provided explicitly, you need to have a <code>firebase-messaging-sw.js</code> at your root location. See [Access the registration token](https://firebase.google.com/docs/cloud-messaging/js/client#access_the_registration_token) for more details. |
26-
| [serviceWorkerRegistrationTimeout](./messaging_.gettokenoptions.md#gettokenoptionsserviceworkerregistrationtimeout) | number | Milliseconds to wait for service worker registration to complete before rejecting and throwing an error. Defaults to 10000. |
2726
| [vapidKey](./messaging_.gettokenoptions.md#gettokenoptionsvapidkey) | string | The public server key provided to push services. The key is used to authenticate push subscribers to receive push messages only from sending servers that hold the corresponding private key. If it is not provided, a default VAPID key is used. Note that some push services (Chrome Push Service) require a non-default VAPID key. Therefore, it is recommended to generate and import a VAPID key for your project with [Configure Web Credentials with FCM](https://firebase.google.com/docs/cloud-messaging/js/client#configure_web_credentials_in_your_app)<!-- -->. See [The Web Push Protocol](https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol) for details on web push services. |
2827

2928
## GetTokenOptions.serviceWorkerRegistration
@@ -36,16 +35,6 @@ The service worker registration for receiving push messaging. If the registratio
3635
serviceWorkerRegistration?: ServiceWorkerRegistration;
3736
```
3837

39-
## GetTokenOptions.serviceWorkerRegistrationTimeout
40-
41-
Milliseconds to wait for service worker registration to complete before rejecting and throwing an error. Defaults to 10000.
42-
43-
<b>Signature:</b>
44-
45-
```typescript
46-
serviceWorkerRegistrationTimeout?: number;
47-
```
48-
4938
## GetTokenOptions.vapidKey
5039

5140
The public server key provided to push services. The key is used to authenticate push subscribers to receive push messages only from sending servers that hold the corresponding private key. If it is not provided, a default VAPID key is used. Note that some push services (Chrome Push Service) require a non-default VAPID key. Therefore, it is recommended to generate and import a VAPID key for your project with [Configure Web Credentials with FCM](https://firebase.google.com/docs/cloud-messaging/js/client#configure_web_credentials_in_your_app)<!-- -->. See [The Web Push Protocol](https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol) for details on web push services.

docs-devsite/messaging_sw.gettokenoptions.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export interface GetTokenOptions
2323
| Property | Type | Description |
2424
| --- | --- | --- |
2525
| [serviceWorkerRegistration](./messaging_sw.gettokenoptions.md#gettokenoptionsserviceworkerregistration) | ServiceWorkerRegistration | The service worker registration for receiving push messaging. If the registration is not provided explicitly, you need to have a <code>firebase-messaging-sw.js</code> at your root location. See [Access the registration token](https://firebase.google.com/docs/cloud-messaging/js/client#access_the_registration_token) for more details. |
26-
| [serviceWorkerRegistrationTimeout](./messaging_sw.gettokenoptions.md#gettokenoptionsserviceworkerregistrationtimeout) | number | Milliseconds to wait for service worker registration to complete before rejecting and throwing an error. Defaults to 10000. |
2726
| [vapidKey](./messaging_sw.gettokenoptions.md#gettokenoptionsvapidkey) | string | The public server key provided to push services. The key is used to authenticate push subscribers to receive push messages only from sending servers that hold the corresponding private key. If it is not provided, a default VAPID key is used. Note that some push services (Chrome Push Service) require a non-default VAPID key. Therefore, it is recommended to generate and import a VAPID key for your project with [Configure Web Credentials with FCM](https://firebase.google.com/docs/cloud-messaging/js/client#configure_web_credentials_in_your_app)<!-- -->. See [The Web Push Protocol](https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol) for details on web push services. |
2827

2928
## GetTokenOptions.serviceWorkerRegistration
@@ -36,16 +35,6 @@ The service worker registration for receiving push messaging. If the registratio
3635
serviceWorkerRegistration?: ServiceWorkerRegistration;
3736
```
3837

39-
## GetTokenOptions.serviceWorkerRegistrationTimeout
40-
41-
Milliseconds to wait for service worker registration to complete before rejecting and throwing an error. Defaults to 10000.
42-
43-
<b>Signature:</b>
44-
45-
```typescript
46-
serviceWorkerRegistrationTimeout?: number;
47-
```
48-
4938
## GetTokenOptions.vapidKey
5039

5140
The public server key provided to push services. The key is used to authenticate push subscribers to receive push messages only from sending servers that hold the corresponding private key. If it is not provided, a default VAPID key is used. Note that some push services (Chrome Push Service) require a non-default VAPID key. Therefore, it is recommended to generate and import a VAPID key for your project with [Configure Web Credentials with FCM](https://firebase.google.com/docs/cloud-messaging/js/client#configure_web_credentials_in_your_app)<!-- -->. See [The Web Push Protocol](https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol) for details on web push services.

packages/messaging/src/api/deleteToken.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ import { deleteTokenInternal } from '../internals/token-manager';
2222
import { registerDefaultSw } from '../helpers/registerDefaultSw';
2323

2424
export async function deleteToken(
25-
messaging: MessagingService,
26-
swRegistrationTimeoutMillis?: number
25+
messaging: MessagingService
2726
): Promise<boolean> {
2827
if (!navigator) {
2928
throw ERROR_FACTORY.create(ErrorCode.AVAILABLE_IN_WINDOW);
3029
}
3130

3231
if (!messaging.swRegistration) {
33-
await registerDefaultSw(messaging, swRegistrationTimeoutMillis);
32+
await registerDefaultSw(messaging);
3433
}
3534

3635
return deleteTokenInternal(messaging);

packages/messaging/src/api/getToken.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export async function getToken(
4242
await updateVapidKey(messaging, options?.vapidKey);
4343
await updateSwReg(
4444
messaging,
45-
options?.serviceWorkerRegistration,
46-
options?.serviceWorkerRegistrationTimeout
45+
options?.serviceWorkerRegistration
4746
);
4847

4948
return getTokenInternal(messaging);

packages/messaging/src/helpers/registerDefaultSw.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import { ERROR_FACTORY, ErrorCode } from '../util/errors';
2525
import { MessagingService } from '../messaging-service';
2626

2727
export async function registerDefaultSw(
28-
messaging: MessagingService,
29-
swRegistrationTimeoutMillis?: number
28+
messaging: MessagingService
3029
): Promise<void> {
3130
try {
3231
messaging.swRegistration = await navigator.serviceWorker.register(
@@ -45,8 +44,7 @@ export async function registerDefaultSw(
4544
/* it is non blocking and we don't care if it failed */
4645
});
4746
await waitForRegistrationActive(
48-
messaging.swRegistration,
49-
swRegistrationTimeoutMillis
47+
messaging.swRegistration
5048
);
5149
} catch (e) {
5250
throw ERROR_FACTORY.create(ErrorCode.FAILED_DEFAULT_REGISTRATION, {
@@ -65,18 +63,17 @@ export async function registerDefaultSw(
6563
* to become "active".
6664
*/
6765
async function waitForRegistrationActive(
68-
registration: ServiceWorkerRegistration,
69-
swRegistrationTimeoutMillis: number = DEFAULT_REGISTRATION_TIMEOUT
66+
registration: ServiceWorkerRegistration
7067
): Promise<void> {
7168
return new Promise<void>((resolve, reject) => {
7269
const rejectTimeout = setTimeout(
7370
() =>
7471
reject(
7572
new Error(
76-
`Service worker not registered after ${swRegistrationTimeoutMillis} ms`
73+
`Service worker not registered after ${DEFAULT_REGISTRATION_TIMEOUT} ms`
7774
)
7875
),
79-
swRegistrationTimeoutMillis
76+
DEFAULT_REGISTRATION_TIMEOUT
8077
);
8178
const incomingSw = registration.installing || registration.waiting;
8279
if (registration.active) {

packages/messaging/src/helpers/updateSwReg.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import { registerDefaultSw } from './registerDefaultSw';
2222

2323
export async function updateSwReg(
2424
messaging: MessagingService,
25-
swRegistration?: ServiceWorkerRegistration | undefined,
26-
swRegistrationTimeoutMillis?: number
25+
swRegistration?: ServiceWorkerRegistration | undefined
2726
): Promise<void> {
2827
if (!swRegistration && !messaging.swRegistration) {
29-
await registerDefaultSw(messaging, swRegistrationTimeoutMillis);
28+
await registerDefaultSw(messaging);
3029
}
3130

3231
if (!swRegistration && !!messaging.swRegistration) {

packages/messaging/src/interfaces/public-types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ export interface GetTokenOptions {
132132
* for more details.
133133
*/
134134
serviceWorkerRegistration?: ServiceWorkerRegistration;
135-
/**
136-
* Milliseconds to wait for service worker registration to complete before
137-
* rejecting and throwing an error. Defaults to 10000.
138-
*/
139-
serviceWorkerRegistrationTimeout?: number;
140135
}
141136

142137
/**

0 commit comments

Comments
 (0)