Simple wrapper for cross-browser usage of the JavaScript Fullscreen API
Installations
npm install screenfull
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
^14.13.1 || >=16.0.0
Node Version
14.19.2
NPM Version
8.3.2
Score
99.5
Supply Chain
99.5
Quality
76
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
HTML (49.63%)
JavaScript (37.89%)
TypeScript (12.48%)
Developer
Download Statistics
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
GitHub Statistics
7,094 Stars
195 Commits
695 Forks
141 Watching
1 Branches
25 Contributors
Sponsor this package
Package Meta Information
Latest Version
6.0.2
Package Id
screenfull@6.0.2
Unpacked Size
17.38 kB
Size
4.98 kB
File Count
5
NPM Version
8.3.2
Node Version
14.19.2
Total Downloads
Cumulative downloads
Total Downloads
0
Last day
0%
0
Compared to previous day
Last week
0%
0
Compared to previous week
Last month
0%
0
Compared to previous month
Last year
0%
0
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
screenfull
Simple wrapper for cross-browser usage of the JavaScript Fullscreen API, which lets you bring the page or any element into fullscreen. Smoothens out the browser implementation differences, so you don't have to.
This package is ESM. Please familiarize yourself with that that implies.
If you cannot use ESM or need to support older browsers without using transpilation, use version 5.2.0.
This package is feature complete. No new features will be accepted.
Demo
Install
Only 0.7 kB gzipped.
1npm install screenfull
Also available on cdnjs (older version).
Why?
Screenfull
1import screenfull from 'screenfull'; 2 3if (screenfull.isEnabled) { 4 screenfull.request(); 5}
Vanilla JavaScript
1document.fullscreenEnabled = 2 document.fullscreenEnabled || 3 document.mozFullScreenEnabled || 4 document.documentElement.webkitRequestFullScreen; 5 6function requestFullscreen(element) { 7 if (element.requestFullscreen) { 8 element.requestFullscreen(); 9 } else if (element.mozRequestFullScreen) { 10 element.mozRequestFullScreen(); 11 } else if (element.webkitRequestFullScreen) { 12 element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); 13 } 14} 15 16if (document.fullscreenEnabled) { 17 requestFullscreen(document.documentElement); 18} 19 20// This is not even entirely comprehensive. There's more.
Support
Note: Safari is supported on desktop and iPad, but not on iPhone. This is a limitation in the browser, not in Screenfull.
Documentation
Examples
Fullscreen the page
1import screenfull from 'screenfull'; 2 3document.getElementById('button').addEventListener('click', () => { 4 if (screenfull.isEnabled) { 5 screenfull.request(); 6 } else { 7 // Ignore or do something else 8 } 9});
Fullscreen an element
1import screenfull from 'screenfull'; 2 3const element = document.getElementById('target'); 4 5document.getElementById('button').addEventListener('click', () => { 6 if (screenfull.isEnabled) { 7 screenfull.request(element); 8 } 9});
Hide navigation user-interface on mobile devices
1import screenfull from 'screenfull'; 2 3const element = document.getElementById('target'); 4 5document.getElementById('button').addEventListener('click', () => { 6 if (screenfull.isEnabled) { 7 screenfull.request(element, {navigationUI: 'hide'}); 8 } 9});
Fullscreen an element with jQuery
1import screenfull from 'screenfull'; 2 3const element = $('#target')[0]; // Get DOM element from jQuery collection 4 5$('#button').on('click', () => { 6 if (screenfull.isEnabled) { 7 screenfull.request(element); 8 } 9});
Toggle fullscreen on a image with jQuery
1import screenfull from 'screenfull'; 2 3$('img').on('click', event => { 4 if (screenfull.isEnabled) { 5 screenfull.toggle(event.target); 6 } 7});
Detect fullscreen change
1import screenfull from 'screenfull'; 2 3if (screenfull.isEnabled) { 4 screenfull.on('change', () => { 5 console.log('Am I fullscreen?', screenfull.isFullscreen ? 'Yes' : 'No'); 6 }); 7}
Remove listeners with:
1import screenfull from 'screenfull'; 2 3screenfull.off('change', callback);
Detect fullscreen error
1import screenfull from 'screenfull'; 2 3if (screenfull.isEnabled) { 4 screenfull.on('error', event => { 5 console.error('Failed to enable fullscreen', event); 6 }); 7}
See the demo for more examples, and view the source.
Fullscreen an element with Angular.js
You can use the Angular.js binding to do something like:
1<div ngsf-fullscreen> 2 <p>This is a fullscreen element</p> 3 <button ngsf-toggle-fullscreen>Toggle fullscreen</button> 4</div>
Fullscreen the page with Angular 2
1import {Directive, HostListener} from '@angular/core'; 2import screenfull from 'screenfull'; 3 4@Directive({ 5 selector: '[toggleFullscreen]' 6}) 7export class ToggleFullscreenDirective { 8 @HostListener('click') onClick() { 9 if (screenfull.isEnabled) { 10 screenfull.toggle(); 11 } 12 } 13}
1<button toggleFullscreen>Toggle fullscreen<button>
API
.request(element, options?)
Make an element fullscreen.
Accepts a DOM element and FullscreenOptions
.
The default element is <html>
. If called with another element than the currently active, it will switch to that if it's a descendant.
If your page is inside an <iframe>
you will need to add a allowfullscreen
attribute (+ webkitallowfullscreen
and mozallowfullscreen
).
Keep in mind that the browser will only enter fullscreen when initiated by user events like click, touch, key.
Returns a promise that resolves after the element enters fullscreen.
.exit()
Brings you out of fullscreen.
Returns a promise that resolves after the element exits fullscreen.
.toggle(element, options?)
Requests fullscreen if not active, otherwise exits.
Accepts a DOM element and FullscreenOptions
.
Returns a promise that resolves after the element enters/exits fullscreen.
.on(event, function)
Events: 'change' | 'error'
Add a listener for when the browser switches in and out of fullscreen or when there is an error.
.off(event, function)
Remove a previously registered event listener.
.onchange(function)
Alias for .on('change', function)
.onerror(function)
Alias for .on('error', function)
.isFullscreen
Returns a boolean whether fullscreen is active.
.element
Returns the element currently in fullscreen, otherwise undefined
.
.isEnabled
Returns a boolean whether you are allowed to enter fullscreen. If your page is inside an <iframe>
you will need to add a allowfullscreen
attribute (+ webkitallowfullscreen
and mozallowfullscreen
).
.raw
Exposes the raw properties (prefixed if needed) used internally: requestFullscreen
, exitFullscreen
, fullscreenElement
, fullscreenEnabled
, fullscreenchange
, fullscreenerror
FAQ
How can I navigate to a new page when fullscreen?
That's not supported by browsers for security reasons. There is, however, a dirty workaround. Create a seamless iframe that fills the screen and navigate to the page in that instead.
1import screenfull from 'screenfull'; 2 3document.querySelector('#new-page-button').addEventListener(() => { 4 const iframe = document.createElement('iframe') 5 6 iframe.setAttribute('id', 'external-iframe'); 7 iframe.setAttribute('src', 'https://new-page-website.com'); 8 iframe.setAttribute('frameborder', 'no'); 9 iframe.style.position = 'absolute'; 10 iframe.style.top = '0'; 11 iframe.style.right = '0'; 12 iframe.style.bottom = '0'; 13 iframe.style.left = '0'; 14 iframe.style.width = '100%'; 15 iframe.style.height = '100%'; 16 17 document.body.prepend(iframe); 18 document.body.style.overflow = 'hidden'; 19});
Resources
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/screenfull/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/screenfull/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:20
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to screenfull
@types/screenfull
Stub TypeScript definitions entry for screenfull, which provides its own types definitions
screenfull-react
Full screen experiences for mobile
es-screenfull
Simple wrapper for cross-browser usage of the JavaScript Fullscreen API, which lets you bring the page or any element into fullscreen.
@ngx-extensions/screenfull
Wrapper module for screenfull