Table of Contents

Class PushManager

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The PushManager interface of the Push API provides a way to receive notifications from third-party servers as well as request URLs for push notifications.

[Value("PushManager")]
public class PushManager
Inheritance
PushManager
Inherited Members

Remarks

This interface is accessed via the PushManager property.

-Push API
-Service Worker API

See also on MDN

Constructors

PushManager()

public PushManager()

Properties

SupportedContentEncodings

The supportedContentEncodings read-only static property of the PushManager interface returns an array of supported content codings that can be used to encrypt the payload of a push message.

[Value("supportedContentEncodings")]
public static string[] SupportedContentEncodings { get; }

Property Value

string[]

An array of strings.
This usually contains just one value: "aes128gcm".

Remarks

User agents must support the aes128gcm content coding defined in {{rfc("8291")}}, and may also support content codings defined from previous versions of the specification.
The returned array is frozen, and may not be modified by the recipient.

The application server requires this coding in order to encrypt push messages for sending to the push server.
The coding used for encryption is also included by the app server in the Content-Encoding HTTP header field of each push message.

The specification does not define how the client code should send the application server the supported codings, or the information in the PushSubscription that it also needs in order to encrypt and send a push message.
One approach is shown in the examples section below.

See also on MDN

Methods

GetSubscription()

The PushManager.getSubscription() method of the PushManager interface retrieves an existing push subscription.

[Value("getSubscription")]
public Task<PushSubscription?> GetSubscription()

Returns

Task<PushSubscription>

A {{jsxref("Promise")}} that resolves to a PushSubscription object or null.

Remarks

It returns a {{jsxref("Promise")}} that resolves to a PushSubscription object containing details of an existing subscription. If no existing subscription exists, this resolves to a null value.

See also on MDN

PermissionState(PushSubscriptionOptionsInit)

The permissionState() method of the
PushManager interface returns a {{jsxref("Promise")}} that resolves to a
string indicating the permission state of the push manager. Possible
values are &apos;prompt&apos;, &apos;denied&apos;, or &apos;granted&apos;.

[Value("permissionState")]
public Task<PermissionState> PermissionState(PushSubscriptionOptionsInit options = null)

Parameters

options PushSubscriptionOptionsInit

Returns

Task<PermissionState>

A Promise that resolves to a string with a value of
&apos;prompt&apos;, &apos;denied&apos;, or &apos;granted&apos;.

Remarks

NOTE

As of Firefox 44, the permissions for Notifications and Push have been merged. If permission is
granted for notifications, push will also be enabled.

See also on MDN

Subscribe(PushSubscriptionOptionsInit)

The subscribe() method of the PushManager
interface subscribes to a push service.

[Value("subscribe")]
public Task<PushSubscription> Subscribe(PushSubscriptionOptionsInit options = null)

Parameters

options PushSubscriptionOptionsInit

Returns

Task<PushSubscription>

A {{jsxref("Promise")}} that resolves to a PushSubscription object.

Remarks

It returns a {{jsxref("Promise")}} that resolves to a PushSubscription
object containing details of a push subscription. A new push subscription is created if
the current service worker does not have an existing subscription.

See also on MDN