The PushEvent() constructor creates a PushEvent in a service worker—the object behind the push and pushsubscriptionchange events in the Push API. Learn type, the optional data payload, PushMessageData, secure-context rules, and how it extends ExtendableEvent—with five examples and try-it labs.
01
Create
new PushEvent()
02
Types
push / subscription
03
Data
PushMessageData
04
Context
Service worker
05
Extends
ExtendableEvent
06
Status
Baseline Mar 2023
Fundamentals
Introduction
Web push lets an application server send messages to a subscribed browser even when your site is closed. When a push arrives, the browser wakes the service worker and fires a push event. The handler receives a PushEvent with optional payload bytes in event.data.
The PushEvent() constructor lets you create that event object yourself—mainly for tests, tooling, or learning how data is wrapped as PushMessageData. MDN notes it is exposed only in a service worker context.
💡
Beginner tip
You will not find PushEvent on window in DevTools on a normal page. Open your service worker script or use the try-it labs, which register a short-lived worker to run the constructor.
Concept
Understanding the PushEvent() Constructor
Pass an event type string and an optional options object. The constructor returns a new PushEvent instance.
type — "push" or "pushsubscriptionchange" (case-sensitive).
data — optional payload; becomes event.data as PushMessageData.
Inherits — ExtendableEvent options such as bubbles and cancelable.
Secure context — Push API features require HTTPS (or localhost).
Production use — real pushes are delivered by the browser; you listen with self.addEventListener("push", ...).
Foundation
📝 Syntax
JavaScript
new PushEvent(type)
new PushEvent(type, options)
Parameters
type — A string with the name of the event.
options(optional) — In addition to ExtendableEvent fields, may include data.
Option fields (MDN)
Option
Meaning
data
Payload bytes; wrapped as PushMessageData on event.data
bubbles
From ExtendableEvent / Event (default false)
cancelable
Whether the event can be cancelled (default false)
Return value
A new PushEvent object.
Compare
⚖️ PushEvent vs Related APIs
API
Use when
new PushEvent(type, { data })
Build a push event object in a service worker (tests / learning)
self.addEventListener("push", ...)
Handle real push messages from the browser
event.data.text() / json()
Read the PushMessageData payload
new Event(type)
Generic synthetic events on window or workers
navigator.serviceWorker
Register the worker that receives push events
Cheat Sheet
⚡ Quick Reference
Goal
Code
MDN text payload
new PushEvent("push", { data: "Some sample text" })
Read text
event.data.text()
Read JSON
event.data.json()
Subscription change
new PushEvent("pushsubscriptionchange")
Listen for real push
self.addEventListener("push", (e) => { ... })
MDN status
Baseline Widely available (since March 2023)
Snapshot
🔍 At a Glance
Four facts to remember about new PushEvent().
Returns
PushEvent
Push API event
Context
SW only
Service worker
Payload
.data
PushMessageData
Baseline
Mar 2023
Widely available
Hands-On
Examples Gallery
Examples follow MDN PushEvent(). Run them in a service worker. Use View Output or Try It Yourself.
📚 Getting Started
Create PushEvent objects and read data.
Example 1 — MDN: Text data Option
Official MDN sample—constructor sets PushMessageData.
The PushEvent() constructor is Baseline Widely available on MDN (since March 2023). It requires a secure context and is exposed in service workers. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
PushEvent() constructor
Create PushEvent objects in service workers for the Push API.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerNo PushEvent / service workers
Not supported
PushEvent()Excellent
Bottom line: Use new PushEvent in service workers; listen for real pushes with addEventListener on self.
Wrap Up
Conclusion
new PushEvent(type, options) builds a PushEvent in a service worker. Pass "push" or "pushsubscriptionchange", optionally set data, then read event.data with text() or json(). In production, the browser delivers real push events—the constructor is mainly for tests and learning.
Use event.data.json() for structured server payloads
Call event.waitUntil() in real push handlers
Feature-detect "serviceWorker" in navigator on pages
Handle missing event.data for silent pushes
❌ Don’t
Expect PushEvent on window in a normal page
Confuse the constructor with browser-delivered push events
Skip secure context (HTTPS) for push features
Assume json() works on invalid JSON strings
Block the worker without waitUntil during notifications
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about PushEvent()
Service-worker push events and payload data.
5
Core concepts
🔔01
new PushEvent
type + data
API
📦02
.data
PushMessageData
Payload
🔒03
SW only
not on window
Context
🔄04
push / change
event types
Types
🎯05
Baseline
since Mar 2023
Status
❓ Frequently Asked Questions
new PushEvent(type, options) creates a PushEvent object. It is exposed only in a service worker context and represents a push message received from an application server.
No. MDN marks the PushEvent() constructor as Baseline Widely available (since March 2023). It is not Deprecated, Experimental, or Non-standard.
Only inside a service worker global scope, in a secure context (HTTPS or localhost). It is not available on the main window thread.
MDN says the type is case-sensitive. Browsers use push for incoming push messages and pushsubscriptionchange when a push subscription changes.
An optional data value (string, ArrayBuffer, or similar). The resulting PushEvent.data property is a PushMessageData object you can read with text(), json(), arrayBuffer(), or blob().
addEventListener listens for push events the browser delivers. The constructor lets you create a PushEvent object manually—useful for tests or learning how event.data is shaped.
Did you know?
MDN’s PushEvent page shows a full push listener that reads event.data?.json() and calls showNotification—that is how most PWAs surface push messages to users.