vue-element-admin Screenfull Implementation: Code, Browser Permissions, and Security Requirements

The vue-element-admin screenfull feature uses the screenfull npm package to wrap the native Fullscreen API, requiring only a user gesture and HTTPS secure context without explicit browser permission prompts.

The vue-element-admin repository by PanJiaChen implements fullscreen functionality through a lightweight Vue component that abstracts cross-browser compatibility complexities. This implementation provides a seamless toggle button in the navigation bar while automatically handling security constraints and browser support detection. Understanding the screenfull implementation helps developers customize fullscreen behavior and troubleshoot permission issues across different deployment environments.

How the Screenfull Feature is Implemented in vue-element-admin

Core Component Architecture

The fullscreen logic resides in src/components/Screenfull/index.vue, which imports the screenfull library and manages state through a local isFullscreen boolean. The component registers a change event listener during the mounted lifecycle hook to synchronize the UI when fullscreen state changes externally, and cleans up the listener in beforeDestroy to prevent memory leaks.

Key implementation details from the source:

  • Import statement: import screenfull from 'screenfull'
  • Data property: data() { return { isFullscreen: false } }
  • Event registration: screenfull.on('change', this.change) in mounted via this.init()
  • Cleanup: screenfull.off('change', this.change) in beforeDestroy via this.destroy()

Integration with the Navigation Bar

The Screenfull component is instantiated within the top navigation bar in src/layout/components/Navbar.vue, where it appears as a clickable icon alongside other right-menu items. This placement ensures the fullscreen toggle is accessible from any view within the application without requiring additional imports in individual pages.

State Management and Event Handling

When a user clicks the icon, the component's click method first verifies browser support via screenfull.enabled. If unsupported, it displays a warning message; otherwise, it calls screenfull.toggle() to enter or exit fullscreen mode. The change method updates the local isFullscreen property based on screenfull.isFullscreen, which drives the conditional rendering of "enter" versus "exit" SVG icons in the template.

// From src/components/Screenfull/index.vue
click() {
  if (!screenfull.enabled) {
    this.$message({
      message: 'you browser can not work',
      type: 'warning'
    })
    return false
  }
  screenfull.toggle()
}

Browser Permissions and Security Requirements for Fullscreen Mode

User Gesture Requirement

Browsers mandate that fullscreen requests originate from a direct user interaction, such as a click or key press. The vue-element-admin implementation satisfies this constraint by binding the fullscreen toggle to an @click handler on the SVG icon, ensuring the API call occurs within the context of a user gesture.

Secure Context (HTTPS) Constraint

Modern browsers restrict the Fullscreen API to secure contexts, meaning the application must be served over HTTPS or from localhost. HTTP deployments will fail silently or throw security errors when attempting to enter fullscreen, making SSL/TLS configuration essential for production environments using this feature.

Browser Support Detection

The component implements defensive programming by checking screenfull.enabled before invoking fullscreen methods. This boolean property returns false on browsers lacking Fullscreen API support (such as legacy Internet Explorer versions), allowing the application to display a fallback warning rather than throwing runtime errors.

Permission Prompt Behavior

Unlike camera or microphone access, the Fullscreen API does not trigger an explicit permission dialog. The browser either grants the request immediately (when initiated by a user gesture on a secure origin) or denies it silently. Users can exit fullscreen at any time by pressing the Esc key, which fires the change event and updates the component state accordingly.

Practical Code Examples

Using the Built-in Component

The Screenfull component is already integrated into the default layout. To use it in custom layouts, import and register the component:

<template>
  <div class="custom-navbar">
    <screenfull class="right-menu-item" />
  </div>
</template>

<script>
import Screenfull from '@/components/Screenfull'

export default {
  components: { Screenfull }
}
</script>

Programmatic Fullscreen Control

For custom fullscreen logic outside the component, import the screenfull library directly:

import screenfull from 'screenfull'

export function toggleFullscreen(element = document.documentElement) {
  if (screenfull.isEnabled) {
    screenfull.toggle(element)  // Must be called within a user gesture
  } else {
    console.warn('Fullscreen API not supported')
  }
}

export function exitFullscreen() {
  if (screenfull.isEnabled && screenfull.isFullscreen) {
    screenfull.exit()
  }
}

Listening for Fullscreen Changes

To react to fullscreen state changes globally:

import screenfull from 'screenfull'

if (screenfull.isEnabled) {
  screenfull.on('change', () => {
    console.log('Fullscreen state:', screenfull.isFullscreen)
    // Update Vuex store or emit events here
  })
}

Summary

  • The vue-element-admin screenfull implementation relies on the screenfull npm package (v4.2.0) to abstract the native Fullscreen API across browsers.
  • Core logic resides in src/components/Screenfull/index.vue, integrated into the navigation bar at src/layout/components/Navbar.vue.
  • Browser requirements include a user gesture (click interaction) and a secure context (HTTPS or localhost) enforced by modern browsers.
  • The component checks screenfull.enabled to handle unsupported browsers gracefully, displaying a warning when the API is unavailable.
  • No explicit permission prompts are required; fullscreen requests are either granted immediately or denied silently based on security context and user interaction.

Frequently Asked Questions

Does vue-element-admin require special permissions for fullscreen mode?

No explicit permissions are required. The Fullscreen API operates without permission dialogs, relying instead on browser-enforced security constraints. The request must originate from a user gesture on a secure HTTPS origin, but users do not need to grant specific permissions through a browser prompt.

Why does fullscreen not work on HTTP sites?

Modern browsers restrict the Fullscreen API to secure contexts as a security measure against phishing and spoofing attacks. When served over HTTP, the browser silently denies fullscreen requests to prevent malicious sites from mimicking system interfaces. You must deploy the application over HTTPS or test on localhost for fullscreen functionality to work.

How do I check if the browser supports fullscreen before calling it?

The screenfull library exposes an isEnabled property (referred to as enabled in version 4.2.0 used by vue-element-admin) that detects native Fullscreen API support. In the vue-element-admin component, this check appears as if (!screenfull.enabled) before attempting to toggle fullscreen, allowing you to display fallback UI or warning messages for unsupported browsers like legacy Internet Explorer.

Can I trigger fullscreen without a user click in vue-element-admin?

No. Browser security policies mandate that fullscreen requests must occur within the handler of a user-generated event, such as a click or keypress. Attempting to call screenfull.toggle() outside of an event handler, such as in a setTimeout, setInterval, or during the mounted lifecycle hook, will result in the browser silently ignoring the request.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →