打开 devtools 是否触发了事件?

Is there an event triggered for opening a devtools?

从问题标题可以看出,我需要一个与打开开发工具相关的事件的回调,比如

    /* I expect for something like that with var "devtools" as window's object or the instanceof an unknowed class  */

    devtools.onDevtoolsOpened = () =>
    {
        // do my stuff
    }

如果可以的话,我会寻求帮助。但如果没有,是否有相关的动作或其他方式来实现我的愿望?

这真的取决于每个浏览器。但是,我发现了一个模块可以为大多数浏览器提供帮助: 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>