The read-only data property on PushEvent returns a PushMessageData object with bytes from the push server—or null for silent pushes. Learn text(), json(), arrayBuffer(), MDN’s notification handler pattern, and safe optional chaining—with five examples and try-it labs.
01
Kind
Instance property
02
Returns
PushMessageData
03
Read-only
no setter
04
Null
silent push
05
Context
Service worker
06
Status
Baseline Mar 2023
Fundamentals
Introduction
When a web push message arrives, the browser wakes your service worker and fires a push event. The handler receives a PushEvent. Its data property is how you read whatever the application server attached to that message.
MDN describes data as a reference to a PushMessageData object—or null if no data member was passed when the event was created. That payload might be plain text, JSON, or raw binary depending on what the server sent.
💡
Beginner tip
Always guard with event.data?.json() ?? {} (or check for null) before reading fields. Silent pushes are valid and data will be null.
Concept
Understanding the data Property
A read-only instance property on PushEvent that exposes the push payload.
Type — PushMessageData or null.
Read-only — you cannot assign to event.data.
Source — bytes sent from the app server to the PushSubscription.
Decryption — browsers decrypt push messages before exposing them via PushMessageData methods.
Reusable — unlike Fetch body readers, MDN says these methods can be called multiple times.
Baseline Widely available on MDN (since March 2023).
Foundation
📝 Syntax
Read data inside a push event handler:
JavaScript
event.data
Return value
A PushMessageData object, or null if no data was included with the push.
Typical pattern (MDN)
JavaScript
self.addEventListener("push", (event) => {
const data = event.data?.json() ?? {};
const title = data.title || "Something Has Happened";
const message =
data.message || "Here's something you might want to check out.";
// show notification using title + message ...
});
The PushEvent.data property 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.data property
Read PushMessageData payloads from push events in service workers.
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.dataExcellent
Bottom line: Use event.data?.json() or text() in push handlers; guard for null on silent pushes.
Wrap Up
Conclusion
PushEvent.data is the read-only gateway to push payloads. It returns PushMessageData (use text(), json(), or binary methods) or null for silent pushes. MDN’s handler pattern with event.data?.json() ?? {} is the safest starting point.
Use event.data?.json() ?? {} with sensible defaults
Call event.waitUntil() for async notification work
Handle silent pushes (data === null) explicitly
Keep JSON payloads small for faster delivery
❌ Don’t
Assume every push includes a JSON body
Read event.data on the main window thread
Call json() on invalid JSON without try/catch
Confuse data with the constructor options.data name—same result, different API surface
Block the worker without waitUntil during async reads
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about data
Push payloads in service worker handlers.
5
Core concepts
📦01
event.data
read-only
Property
📄02
PushMessageData
wrapper
Type
🔒03
null
silent push
Edge case
🔄04
.json()
parse payload
Method
🎯05
Baseline
since Mar 2023
Status
❓ Frequently Asked Questions
A read-only PushMessageData object containing bytes sent from the application server to the PushSubscription—or null if no data was included with the push.
No. MDN marks PushEvent.data as Baseline Widely available (since March 2023). It is not Deprecated, Experimental, or Non-standard.
Inside a service worker push handler: self.addEventListener('push', (event) => { ... event.data ... }). It is not available on the main window thread.
text(), json(), arrayBuffer(), blob(), and bytes() (Uint8Array). Unlike Fetch body methods, MDN says these can be called multiple times on the same object.
When the push message has no payload—often called a silent push used to wake the worker without user-visible content.
Use optional chaining and a fallback: const data = event.data?.json() ?? {}; then read fields like data.title with defaults.
Did you know?
MDN notes that PushMessageData methods can be called multiple times on the same object—unlike Fetch Response.body readers, which are typically single-use.