Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
screenfull
Advanced tools
Simple wrapper for cross-browser usage of the JavaScript Fullscreen API, which lets you bring the page or any element into fullscreen.
The screenfull npm package is a simple wrapper for cross-browser usage of the JavaScript Fullscreen API, which allows web pages to display web content in full-screen mode, exiting this mode, and toggling between these states. It abstracts away the differences between various browsers' implementations of the Fullscreen API, providing a consistent and easy-to-use interface for developers.
Toggle Fullscreen
This feature allows you to toggle fullscreen mode on and off for the page or a specific element. The code checks if fullscreen is supported and enabled, then toggles the fullscreen state.
if (screenfull.isEnabled) {
screenfull.toggle();
}
Enter Fullscreen
This feature enables entering fullscreen mode. The code sample demonstrates how to request the browser to enter fullscreen mode if it is supported.
if (screenfull.isEnabled) {
screenfull.request();
}
Exit Fullscreen
This feature allows you to exit fullscreen mode programmatically. The code checks if fullscreen is enabled and then exits fullscreen mode.
if (screenfull.isEnabled) {
screenfull.exit();
}
Fullscreen Change Event
This feature allows you to listen for changes in the fullscreen state. The code sample demonstrates how to register an event listener that logs the current fullscreen state whenever it changes.
if (screenfull.isEnabled) {
screenfull.on('change', () => {
console.log('Am I fullscreen?', screenfull.isFullscreen ? 'Yes' : 'No');
});
}
fscreen is another abstraction library for the Fullscreen API, similar to screenfull. It provides a unified API for using the Fullscreen API across different browsers. Compared to screenfull, fscreen sticks closely to the original Fullscreen API specification, offering a more minimalistic approach.
bigscreen is a library that offers similar functionality to screenfull, with additional features such as the ability to use fullscreen on multiple monitors and more detailed event handling. It provides a more comprehensive solution for complex fullscreen scenarios but might be overkill for simple use cases.
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.
Only 0.7 kB gzipped.
npm install screenfull
Also available on cdnjs (older version).
import screenfull from 'screenfull';
if (screenfull.isEnabled) {
screenfull.request();
}
document.fullscreenEnabled =
document.fullscreenEnabled ||
document.mozFullScreenEnabled ||
document.documentElement.webkitRequestFullScreen;
function requestFullscreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
}
if (document.fullscreenEnabled) {
requestFullscreen(document.documentElement);
}
// This is not even entirely comprehensive. There's more.
Note: Safari is supported on desktop and iPad, but not on iPhone. This is a limitation in the browser, not in Screenfull.
import screenfull from 'screenfull';
document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request();
} else {
// Ignore or do something else
}
});
import screenfull from 'screenfull';
const element = document.getElementById('target');
document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element);
}
});
import screenfull from 'screenfull';
const element = document.getElementById('target');
document.getElementById('button').addEventListener('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element, {navigationUI: 'hide'});
}
});
import screenfull from 'screenfull';
const element = $('#target')[0]; // Get DOM element from jQuery collection
$('#button').on('click', () => {
if (screenfull.isEnabled) {
screenfull.request(element);
}
});
import screenfull from 'screenfull';
$('img').on('click', event => {
if (screenfull.isEnabled) {
screenfull.toggle(event.target);
}
});
import screenfull from 'screenfull';
if (screenfull.isEnabled) {
screenfull.on('change', () => {
console.log('Am I fullscreen?', screenfull.isFullscreen ? 'Yes' : 'No');
});
}
Remove listeners with:
import screenfull from 'screenfull';
screenfull.off('change', callback);
import screenfull from 'screenfull';
if (screenfull.isEnabled) {
screenfull.on('error', event => {
console.error('Failed to enable fullscreen', event);
});
}
See the demo for more examples, and view the source.
You can use the Angular.js binding to do something like:
<div ngsf-fullscreen>
<p>This is a fullscreen element</p>
<button ngsf-toggle-fullscreen>Toggle fullscreen</button>
</div>
import {Directive, HostListener} from '@angular/core';
import screenfull from 'screenfull';
@Directive({
selector: '[toggleFullscreen]'
})
export class ToggleFullscreenDirective {
@HostListener('click') onClick() {
if (screenfull.isEnabled) {
screenfull.toggle();
}
}
}
<button toggleFullscreen>Toggle fullscreen<button>
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.
Brings you out of fullscreen.
Returns a promise that resolves after the element exits fullscreen.
Requests fullscreen if not active, otherwise exits.
Accepts a DOM element and FullscreenOptions
.
Returns a promise that resolves after the element enters/exits fullscreen.
Events: 'change' | 'error'
Add a listener for when the browser switches in and out of fullscreen or when there is an error.
Remove a previously registered event listener.
Alias for .on('change', function)
Alias for .on('error', function)
Returns a boolean whether fullscreen is active.
Returns the element currently in fullscreen, otherwise undefined
.
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
).
Exposes the raw properties (prefixed if needed) used internally: requestFullscreen
, exitFullscreen
, fullscreenElement
, fullscreenEnabled
, fullscreenchange
, fullscreenerror
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.
import screenfull from 'screenfull';
document.querySelector('#new-page-button').addEventListener(() => {
const iframe = document.createElement('iframe')
iframe.setAttribute('id', 'external-iframe');
iframe.setAttribute('src', 'https://new-page-website.com');
iframe.setAttribute('frameborder', 'no');
iframe.style.position = 'absolute';
iframe.style.top = '0';
iframe.style.right = '0';
iframe.style.bottom = '0';
iframe.style.left = '0';
iframe.style.width = '100%';
iframe.style.height = '100%';
document.body.prepend(iframe);
document.body.style.overflow = 'hidden';
});
FAQs
Simple wrapper for cross-browser usage of the JavaScript Fullscreen API, which lets you bring the page or any element into fullscreen.
The npm package screenfull receives a total of 1,022,622 weekly downloads. As such, screenfull popularity was classified as popular.
We found that screenfull demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.