Fullscreen

The Fullscreen component provides an interface to the Fullscreen API, enabling your Progressive Web App to display content in fullscreen mode. This creates an immersive experience by removing browser chrome and utilizing the entire screen space.

This component is particularly useful for:

  • Media players and video streaming applications

  • Photo galleries and image viewers

  • Presentation and slideshow applications

  • Gaming applications

  • Data visualization and dashboard applications

  • Reading apps and e-books

Browser Support

The Fullscreen API is widely supported in modern browsers. However, browser vendors may have different implementations and require user interaction to activate fullscreen mode.

circle-info

Fullscreen mode can only be triggered by user interaction (click, touch) for security reasons. Programmatic fullscreen requests without user gestures will be blocked.

Usage

Fullscreen for Entire Page

<section {{ stimulus_controller('@pwa/fullscreen') }}>
    <h1>My Presentation</h1>
    <div class="content">
        <!-- Your content here -->
    </div>

    <button {{ stimulus_action('@pwa/fullscreen', 'request', 'click') }}>
        Enter Fullscreen
    </button>

    <button {{ stimulus_action('@pwa/fullscreen', 'exit', 'click') }}>
        Exit Fullscreen
    </button>
</section>

<script>
    document.addEventListener('pwa--fullscreen:change', (event) => {
        const { fullscreen, element } = event.detail;
        console.log('Fullscreen:', fullscreen ? 'active' : 'inactive');
    });
</script>

Fullscreen for Specific Element

Video Player with Fullscreen

Presentation Mode with Navigation

Parameters

None

Actions

request

Triggers fullscreen mode for the entire document or a specific element.

Parameters:

  • target (string, optional): CSS selector for the element to display in fullscreen. If omitted, the entire document enters fullscreen.

Or for a specific element:

circle-exclamation

exit

Exits fullscreen mode and returns to normal display.

Alternatively, users can press the Escape key to exit fullscreen mode (this is a browser feature, not controlled by the component).

Targets

None

Events

pwa--fullscreen:change

Dispatched when fullscreen mode is toggled (entered or exited).

Payload: {fullscreen, element}

  • fullscreen (boolean): true when entering fullscreen, false when exiting

  • element (Element): The element that entered fullscreen

Example:

pwa--fullscreen:error

Dispatched when an error occurs while entering or exiting fullscreen mode.

Payload: {element, error}

  • element (Element): The element that failed to enter fullscreen

  • error (Error): Error object containing details about the failure

Example:

Best Practices

  1. User-initiated only: Always trigger fullscreen from user interactions (clicks, touches)

  2. Provide exit option: Always offer a visible way to exit fullscreen

  3. Handle Escape key: Document that users can press Escape to exit

  4. Responsive design: Ensure your fullscreen content adapts to different screen sizes

  5. Test on devices: Fullscreen behavior may vary across browsers and devices

  6. Communicate state: Clearly indicate when fullscreen mode is active

  7. Preserve content: Ensure fullscreen elements are properly restored when exiting

Common Use Cases

Media Player Controls

Dashboard Fullscreen

Photo Viewer with Gestures

Browser-Specific Considerations

Safari (iOS)

  • On iOS, only video elements can enter fullscreen (not other elements)

  • Fullscreen video is handled by the native player

  • Document-level fullscreen is not supported

Chrome/Edge

  • Full support for element and document fullscreen

  • Provides native fullscreen UI controls

  • Supports custom fullscreen styling with CSS

Firefox

  • Good support with vendor prefixes in older versions

  • Modern versions support standard Fullscreen API

CSS for Fullscreen Mode

You can style elements differently when in fullscreen using CSS:

Troubleshooting

Fullscreen not working

Common issues:

  1. No user interaction: Fullscreen must be triggered by user gesture

  2. Browser permissions: Some browsers block fullscreen by default

  3. Iframe restrictions: Fullscreen may not work in iframes without proper attributes

  4. Mobile Safari: Only video elements support fullscreen

Element not displaying correctly

Solutions:

  1. Check CSS: Ensure fullscreen element has proper styling

  2. Z-index issues: Fullscreen elements should have high z-index

  3. Viewport units: Use 100vw and 100vh for full coverage

  4. Aspect ratio: Maintain proper aspect ratios in fullscreen

Complete Example: Video Player

Last updated

Was this helpful?