JavaScript PushEvent data Property

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

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

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.

Understanding the data Property

A read-only instance property on PushEvent that exposes the push payload.

  • TypePushMessageData 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.
  • Methodstext(), json(), arrayBuffer(), blob(), bytes().
  • Reusable — unlike Fetch body readers, MDN says these methods can be called multiple times.
  • Baseline Widely available on MDN (since March 2023).

📝 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 ...
});

⚡ Quick Reference

GoalCode / note
Read as JSONevent.data?.json() ?? {}
Read as textevent.data?.text()
Silent push?event.data === null
Binary bytesevent.data?.arrayBuffer()
Read-onlyCannot assign to data
MDN statusBaseline Widely available (since March 2023)

🔍 At a Glance

Four facts to remember about PushEvent.data.

Type
PushMessageData

or null

Access
read-only

No setter

Parse
.json()

Common pattern

Baseline
Mar 2023

Widely available

Examples Gallery

Examples follow MDN PushEvent.data. Run in a service worker context. Use View Output or Try It Yourself.

📚 Getting Started

Read push payloads from event.data.

Example 1 — MDN Push Handler with data.json()

Official MDN pattern—parse JSON and show a notification.

JavaScript
self.addEventListener("push", (event) => {
  if (!(self.Notification && self.Notification.permission === "granted")) {
    return;
  }

  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.";

  const notification = new Notification(title, {
    body: message,
    tag: "simple-push-demo-notification",
  });
});
Try It Yourself

How It Works

event.data.json() parses the server payload; defaults cover missing fields.

Example 2 — Read Plain Text with data.text()

When the server sends a UTF-8 string instead of JSON.

JavaScript
self.addEventListener("push", (event) => {
  if (!event.data) {
    console.log("Silent push — no data");
    return;
  }

  const body = event.data.text();
  console.log("Push says:", body);
});
Try It Yourself

How It Works

PushMessageData.text() returns the payload as a string.

📈 Null Checks & Routing

Handle silent pushes and structured actions.

Example 3 — Silent Push (data === null)

MDN: null when no data member was passed.

JavaScript
self.addEventListener("push", (event) => {
  if (event.data === null) {
    console.log("Silent push — wake worker only");
    // sync data, refresh cache, etc.
    return;
  }

  console.log("Payload:", event.data.text());
});
Try It Yourself

How It Works

Silent pushes are valid—always check event.data before calling methods.

Example 4 — Route by action (PushMessageData MDN)

Parse JSON and branch on an action field.

JavaScript
self.addEventListener("push", (event) => {
  const obj = event.data.json();

  if (obj.action === "subscribe" || obj.action === "unsubscribe") {
    console.log("Notify:", obj.action);
  } else if (obj.action === "init" || obj.action === "chatMsg") {
    console.log("Forward:", obj.action);
  }
});
Try It Yourself

How It Works

Servers often send JSON with a discriminator field like action.

Example 5 — Safe Optional Chaining

Combine ?. and ?? for robust handlers.

JavaScript
self.addEventListener("push", (event) => {
  const payload = event.data?.json() ?? {};
  const title = payload.title ?? "Default title";
  const count = payload.count ?? 0;

  console.log(title, count);
});
Try It Yourself

How It Works

If data is null, optional chaining skips json() and the fallback object is used.

🚀 Common Use Cases

  • Show notification title and body from server JSON.
  • Wake the worker on silent push to sync data in the background.
  • Route different push types with an action field.
  • Read binary payloads with arrayBuffer() or bytes().
  • Unit-test push handlers by creating events with new PushEvent(..., { data }).

🔧 How It Works

1

Server sends push

Application server posts encrypted bytes to the push service.

Origin
2

Browser decrypts

The browser decrypts and delivers a PushEvent to the worker.

Delivery
3

Read event.data

PushMessageData wraps the bytes—or null if empty.

Property
4

Parse & act

Call json(), text(), or binary methods; update UI via notifications.

📝 Notes

  • Baseline Widely available (MDN, since March 2023).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Service worker only — read data in push handlers.
  • Secure context — HTTPS or localhost for Push API features.
  • Multi-readPushMessageData methods can be invoked more than once (unlike Fetch bodies).
  • Related learning: PushEvent(), navigator.serviceWorker, Worker(), JavaScript hub.

Universal Browser Support

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.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer No PushEvent / service workers
Not supported
PushEvent.data Excellent

Bottom line: Use event.data?.json() or text() in push handlers; guard for null on silent pushes.

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.

Continue with PushEvent(), navigator.serviceWorker, Worker(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Check event.data before calling json()
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about data

Push payloads in service worker handlers.

5
Core concepts
📄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.

Push encryption codings

Learn supportedContentEncodings—what the app server needs to encrypt pushes.

supportedContentEncodings →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful