JavaScript Document fullscreenerror Event

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Document event
Limited availability

What You’ll Learn

The Document fullscreenerror event fires when the browser cannot switch to fullscreen. Learn why MDN delivers two events (Element, then Document), how to use document.onfullscreenerror, how it pairs with requestFullscreen() Promise rejection, and five try-it labs.

01

Kind

Document event

02

Type

Event

03

Cancelable

No

04

Delivery

Element, then Document

05

Also check

Promise .catch()

06

Status

Limited availability

Introduction

Fullscreen is powerful—and often restricted. If requestFullscreen() is denied, the element does not go fullscreen. Instead you get a fullscreenerror event (and usually a rejected Promise).

Per MDN, two fullscreenerror events fire: the first on the Element that failed to change modes, and the second on the Document that owns that element. Listening on document is the natural place for app-wide error UI.

💡
Beginner tip

The most common beginner mistake is calling requestFullscreen() outside a click/key handler. Many browsers deny that and fire fullscreenerror. MDN marks this API Limited availability (not Baseline)—feature-detect and test.

Understanding fullscreenerror

A Document event that answers: “Did a fullscreen mode change fail?”

  • Fires when the browser cannot switch into (or sometimes out of) fullscreen.
  • Two deliveries — first to the Element, then to its Document (like fullscreenchange).
  • Not cancelable — you cannot force fullscreen by calling preventDefault().
  • Event type — a plain Event (no rich error code on the event itself).
  • Handlerdocument.onfullscreenerror or document.addEventListener("fullscreenerror", ...).
  • Limited availability on MDN (not Baseline)—test carefully.

📝 Syntax

Use the event name with addEventListener, or set the handler property on document:

JavaScript
addEventListener("fullscreenerror", (event) => { });

onfullscreenerror = (event) => { };

Event type

A generic Event. Not cancelable.

MDN Document example

JavaScript
const requestor = document.querySelector("div");

function handleError(event) {
  console.error("an error occurred changing into fullscreen");
  console.log(event);
}

document.addEventListener("fullscreenerror", handleError);
// or
document.onfullscreenerror = handleError;

requestor.requestFullscreen();

Success vs failure path

OutcomeWhat you get
SuccessPromise resolves + fullscreenchange
FailurePromise rejects + fullscreenerror (Element, then Document)

⚠️ Why Fullscreen Requests Fail

  • No user gesture — call from a click/key handler, not a bare timer.
  • Iframe policy — nested frames often need allow="fullscreen".
  • Permissions Policy — the page or parent may block the fullscreen feature.
  • Unsupported content — some element types / plugins cannot go fullscreen.
  • Detached nodes — if the element left the document, events may go to the Document instead.

See MDN’s Guide to the Fullscreen API for more failure cases.

⚖️ fullscreenerror vs fullscreenchange

Topicfullscreenchangefullscreenerror
MeaningMode already changedMode change failed
Typical next stepUpdate UI from fullscreenElementShow error / fallback
PromiseResolves on successRejects on failure
DeliveryElement, then DocumentElement, then Document
Cancelable?NoNo

⚡ Quick Reference

GoalCode / note
Listen (Document)document.addEventListener("fullscreenerror", fn)
Handler propertydocument.onfullscreenerror = fn
Catch Promise tooel.requestFullscreen().catch(handler)
Cancelable?No
Sibling success eventfullscreenchange
MDN statusLimited availability (not Baseline)

🔍 At a Glance

Four facts to remember about Document fullscreenerror.

Event type
Event

Plain Event

Means
FS failed

Could not switch

Also
.catch()

Promise rejects

Baseline
no

Limited availability

Examples Gallery

Examples follow MDN Document: fullscreenerror event and listen on document. Some labs intentionally trigger failures (for example calling without a user gesture).

📚 Getting Started

MDN-style Document listener and the handler property.

Example 1 — Document addEventListener (MDN)

Log when a fullscreen mode change fails; listen on document.

JavaScript
const requestor = document.querySelector("div");

function handleError(event) {
  console.error("an error occurred changing into fullscreen");
  console.log(event);
}

document.addEventListener("fullscreenerror", handleError);
// or
document.onfullscreenerror = handleError;

requestor.requestFullscreen();
Try It Yourself

How It Works

MDN’s sample calls requestFullscreen() immediately. In many browsers that fails; the Element gets the first error event, then Document gets the second—your Document listener still sees it.

Example 2 — document.onfullscreenerror

Update a status line when the Document handler property receives the event.

JavaScript
const el = document.getElementById("fs");
const out = document.getElementById("out");

document.onfullscreenerror = () => {
  out.textContent = "fullscreenerror: could not change mode";
};

document.getElementById("bad").addEventListener("click", () => {
  // Still may fail in some environments (iframe / policy)
  el.requestFullscreen();
});
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners. Keep the property form for tiny demos.

📈 Promise, Gesture & Fallback

Pair the event with Promise rejection, show a common denial, and offer UI fallback.

Example 3 — Event + Promise .catch()

Handle both Document fullscreenerror and requestFullscreen().catch().

JavaScript
const el = document.getElementById("fs");
const out = document.getElementById("out");

document.addEventListener("fullscreenerror", () => {
  out.textContent = "Event: fullscreenerror (on document)";
});

document.getElementById("go").addEventListener("click", () => {
  el.requestFullscreen().catch((err) => {
    out.textContent =
      "Promise rejected: " + (err && err.message ? err.message : String(err));
  });
});
Try It Yourself

How It Works

The event is a generic signal; the Promise rejection often carries a more useful message. Handle both for robust UX.

Example 4 — Delayed Call (No User Gesture)

Arm a timer from a click, then call requestFullscreen later to show a common denial.

JavaScript
const el = document.getElementById("fs");
const out = document.getElementById("out");

document.addEventListener("fullscreenerror", () => {
  out.textContent = "fullscreenerror (likely no user gesture / policy)";
});

document.getElementById("arm").addEventListener("click", () => {
  out.textContent = "Calling requestFullscreen in 500ms without a gesture...";
  setTimeout(() => {
    el.requestFullscreen().catch(() => {
      out.textContent += "\nPromise also rejected.";
    });
  }, 500);
});
Try It Yourself

How It Works

The original click gesture is gone by the time the timer runs. Call requestFullscreen() synchronously inside the click handler instead.

Example 5 — Friendly UI Fallback

On Document fullscreenerror, show a message and apply a CSS maximized windowed layout.

JavaScript
const el = document.getElementById("fs");
const msg = document.getElementById("msg");

document.addEventListener("fullscreenerror", () => {
  msg.textContent =
    "Fullscreen blocked here. Using a large windowed layout instead.";
  el.classList.add("is-maximized");
});

document.addEventListener("fullscreenchange", () => {
  if (document.fullscreenElement) {
    msg.textContent = "Fullscreen OK";
    el.classList.remove("is-maximized");
  }
});

document.getElementById("go").addEventListener("click", () => {
  el.requestFullscreen().catch(() => {});
});
Try It Yourself

How It Works

Never leave the user stuck. Pair error handling with a usable fallback so video, games, or slides still work in windowed mode.

🚀 Common Use Cases

  • Toast / banner when a fullscreen button is denied.
  • Falling back to a maximized in-page layout.
  • Logging analytics for fullscreen permission failures.
  • Teaching why user gestures matter for privileged APIs.
  • One Document listener covering errors from any fullscreen widget.

🔧 How It Works

1

Request fullscreen

Code calls element.requestFullscreen() (or exit fails).

Request
2

Browser denies

Gesture, iframe, policy, or engine rules block the switch.

Deny
3

Two error events

First on the Element, then on the Document; Promise rejects.

Notify
4

Show fallback UI

Message the user and keep a non-fullscreen experience working.

📝 Notes

  • MDN: Limited availability (not Baseline)—test the browsers you support.
  • Not Deprecated, Experimental, or Non-standard—no status banner required.
  • Not cancelable; pair with Promise .catch() for richer messages.
  • Two deliveries: Element first, then Document.
  • Related learning: fullscreenchange, exitFullscreen(), fullscreenEnabled, JavaScript hub.

Limited Availability Support

Document fullscreenerror is marked Limited availability on MDN (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. Feature-detect Fullscreen API methods, and remember iframes and permissions can still block fullscreen.

Limited availability

Document fullscreenerror

Failure signal when fullscreen cannot start (or sometimes exit). Confirm support and permissions in your target browsers.

Limited Not Baseline
Google Chrome Supported (check BCD / iframe policy)
Supported
Mozilla Firefox Supported in modern versions
Supported
Apple Safari Supported with platform quirks
Supported
Microsoft Edge Supported · Chromium
Supported
Opera Supported · Modern versions
Supported
Internet Explorer No modern Fullscreen API
No
fullscreenerror Limited

Bottom line: Listen on document for fullscreenerror, also handle requestFullscreen().catch(), and always provide a non-fullscreen fallback.

Conclusion

Document fullscreenerror is your safety net when fullscreen is denied. Listen on document for app-wide errors, catch the Promise too, and keep a usable windowed fallback ready.

Continue with pointerlockchange, fullscreenchange, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Listen on document for global fullscreen error UI
  • Also handle requestFullscreen().catch()
  • Call enter fullscreen from a real user gesture
  • Offer a non-fullscreen fallback layout
  • Feature-detect and test iframes / Permissions Policy

❌ Don’t

  • Assume every browser / iframe allows fullscreen
  • Call enter fullscreen from a bare timer
  • Expect preventDefault() to force fullscreen
  • Ignore failures and leave the UI looking broken
  • Assume Baseline Widely available status

Key Takeaways

Knowledge Unlocked

Five things to remember about Document fullscreenerror

Failure signal (Element then Document) — always plan a fallback.

5
Core concepts
🔁 02

Two events

Element → Document

Path
📦 03

Promise

also rejects

API
👋 04

User gesture

required often

Cause
⚠️ 05

Limited avail.

not Baseline

Compat

❓ Frequently Asked Questions

It fires when the browser cannot switch to fullscreen mode. As with fullscreenchange, two fullscreenerror events are fired: first on the Element that failed, then on the Document that owns that element.
No. MDN does not mark Document fullscreenerror as Deprecated, Experimental, or Non-standard. It has Limited availability (not Baseline), so always test the browsers and embedding contexts you care about.
Common reasons: no user gesture, iframe without allow="fullscreen", Permissions Policy blocking fullscreen, unsupported content, or the browser denying permission. See MDN’s Fullscreen API guide.
No. MDN states this event is not cancelable. You cannot force fullscreen with preventDefault().
Either works. MDN’s Document example listens on document. That is handy for app-wide error UI because the second event delivery reaches Document.
Success path: requestFullscreen resolves and fullscreenchange fires. Failure path: the Promise rejects and fullscreenerror fires instead of a successful mode change.
Did you know?

MDN documents the same dual-delivery pattern for both fullscreenchange and fullscreenerror: Element first, Document second. That is why a single Document listener can power both success and failure UI for every fullscreen widget on the page.

Next: Document pointerlockchange

Learn the Document event that fires when the pointer is locked or unlocked.

pointerlockchange →

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