从问题标题可以看出,我需要一个与打开开发工具相关的事件的回调,比如
/* I expect for something like that with var "devtools" as window's object or the instanceof an unknowed class */
devtools.onDevtoolsOpened = () =>
{
// do my stuff
}
如果可能,我会寻求帮助。但如果没有,是否有相关的 Action 或其他方式来实现我的愿望?
最佳答案
这真的取决于每个浏览器。但是,我发现了一个模块可以为大多数浏览器提供帮助:
devtools-detect
来自他们的文档:
<script src="node_modules/devtools-detect/index.js"></script>
<script type="module">
// Check if it's open
console.log('Is DevTools open:', window.devtools.isOpen);
// Check it's orientation, `undefined` if not open
console.log('DevTools orientation:', window.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>
关于javascript - 打开 devtools 是否触发了事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57841500/