@innei/devtools-detector
v2.0.4-beta.1
Published
devtools-detector
Downloads
6
Maintainers
Readme
devtools-detector
Install
npm install devtools-detector --save
Usage
ES6 & TypeScript
import { addListener, launch } from 'devtools-detector';
const view = document.createElement('div');
document.body.appendChild(view);
// 1. add listener
addListener(
isOpen =>
(view.innerText = isOpen
? 'devtools status: open'
: 'devtools status: close')
);
// 2. launch detect
launch();
AMD
require(['devtools-detector'], function(devtoolsDetector) {
var view = document.createElement('div');
document.body.appendChild(view);
devtoolsDetector.addListener(function(isOpen) {
view.innerText = isOpen
? 'devtools status: open'
: 'devtools status: close';
});
devtoolsDetector.launch();
});
No Module System
<script src="node_modules/devtools-detector/lib/devtools-detector.js"></script>
<script>
var view = document.createElement('div');
document.body.appendChild(view);
devtoolsDetector.addListener(function(isOpen) {
view.innerText = isOpen
? 'devtools status: open'
: 'devtools status: close';
});
devtoolsDetector.launch();
</script>
Support
- IE9+ (required Promise polyfill)
- Edge
- Chrome
- Firefox
- Safari
- Opera
Type & API
- DevtoolsDetail
interface DevtoolsDetail {
isOpen: boolean;
checkerName: string;
}
- Listener
type DevtoolsDetectorListener = (isOpen: boolean, detail?: DevtoolsDetail) => void;
launch()
launch detect
isLaunch()
if detect is launched then return
true
, else returnfalse
stop()
stop detect
addListener(listener: DevtoolsDetectorListener)
removeListener(listener: DevtoolsDetectorListener)
setDetectDelay(value: number)
Set detect loop delay time, if value =< 0 then stop detecting.
Caveats
- In Firefox, if DevTools is undocked, detected only when switching to the Console Panel.
- Make sure
devtools-detector
is the first one to load
Reference
License
MIT © AEPKILL