The Notification
To reach the client (web browser), you need to send a Notification to the Subscription.
use WebPush\Notification;
$notification = Notification::create();
The Notification should have a payload. In this case, the payload will be encrypted on server side and decrypted by the client.
That payload may be a string or a JSON object. The structure of the latter is described in the next section.
use WebPush\Notification;
$notification = Notification::create()
->withPayload('Hello world')

TTL (Time-To-Live)

With this feature, a value in seconds is added to the notification. It suggests how long a push message is retained by the push service. A value of 0 (zero) indicates the notification is delivered immediately.
use WebPush\Notification;
$notification = Notification::create()


A push message that has been stored by the push service can be replaced with new content. If the user agent is offline during the time the push messages are sent, updating a push message avoids the situation where outdated or redundant messages are sent to the user agent.
Only push messages that have been assigned a topic can be replaced. A push message with a topic replaces any outstanding push message with an identical topic.
use WebPush\Notification;
$notification = Notification::create()


For a device that is battery-powered, it is often critical it remains dormant for extended periods.
Radio communication in particular consumes significant power and limits the length of time the device can operate.
To avoid consuming resources to receive trivial messages, it is helpful if an application server can communicate the urgency of a message and if the user agent can request that the push server only forwards messages of a specific urgency.
Device State
On power and Wi-Fi
On either power or Wi-Fi
Topic updates
On neither power nor Wi-Fi
Chat or Calendar Message
Low battery
Incoming phone call or time-sensitive alert
Be carful with the very-low urgency: it is not recognized by all Web-Push services
use WebPush\Notification;
$notification = Notification::create()

Asynchronous Response

Your application may prefer asynchronous responses to request confirmation from the push service when a push message is delivered and then acknowledged by the user agent. The push service MUST support delivery confirmations to use this feature.
use WebPush\Notification;
$notification = Notification::create()
->async() // Prefer async response
->sync() // Prefer sync response (default)
The async mode is not recognised by all Web Push services. In case of failure, you should try sending syncnotifications.

JSON Messages

As mentioned in the overview section, the specification defines a structure for the payload. This structure contains properties that the client should be understood and render an appropriate way.
The library provides a WebPush\Message class with convenient methods to ease the creation of a message.
use WebPush\Action;
use WebPush\Message;
use WebPush\Notification;
$message = Message::create('This is the title', null, true)
->mute() // Silent
->unmute() // Not silent (default)
->auto() //Direction = auto (default)
->ltr() //Direction = left to right
->rtl() //Direction = right to left
->addAction(Action::create('alert', 'Click me!'))
->doNotRenotify() // Default
->withBody('Hello World!')
->withData(['foo' => 'BAR']) // Arbitrary data
->vibrate(300, 100, 400)
->toString() // Converts the Message object into a string
$notification = Notification::create()
Please note that the second and the third parameters are needed for v1.1+ branch but bill be removed in v2.0.
The resulting notification payload will look like as follow:
"title":"This is the title",
"title":"Click me!"
"body":"Hello World!",
"l ang":"fr-FR",
On client side, you can easily load that payload and display the notification:
const {title, options} = payload;
const notification = new Notification(title, options);