Skip to content

sindresorhus/devtools-detect

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
October 14, 2021 16:17
October 14, 2021 16:17
October 14, 2021 16:17
December 8, 2022 20:36
October 14, 2021 16:17
October 14, 2021 16:17
December 8, 2022 20:37
March 21, 2023 17:12

devtools-detect

Detect if DevTools is open and its orientation

Useful for when you want something special to happen when DevTools is open. Like pausing canvas, adding style debug info, etc.

This package has a lot of flaws. It used to work better, but browsers changed, and the detection now has too many false-positives.

Demo

Install

npm install devtools-detect

Usage

<script type="module">
	import devtools from './node_modules/devtools-detect/index.js';

	// Check if it's open
	console.log('Is DevTools open:', devtools.isOpen);

	// Check it's orientation, `undefined` if not open
	console.log('DevTools orientation:', devtools.orientation);

	// Get notified when it's opened/closed or orientation changes
	window.addEventListener('devtoolschange', event => {
		console.log('Is DevTools open:', event.detail.isOpen);
		console.log('DevTools orientation:', event.detail.orientation);
	});
</script>

Support

  • Chrome DevTools
  • Safari DevTools
  • Firefox DevTools
  • Opera DevTools

Caveats

Doesn't work if DevTools is undocked and will show false positive if you toggle any kind of sidebar.