[Vuejs]-Is there a way to detect browser events (console) with vue/nuxt explicitly?

0👍

As mentioned in "detect-devtools" documentation, we can get devtools value like this:

console.log('Is DevTools open:', window.devtools.isOpen);

The problem here is window object is not reactive.

If you don’t mind a little delay, we can use an interval to update our reactive data:

  data: {
    devtools: null;
  },
  mounted() {
    this.interval = setInterval(()=>{
      this.devtools = window.devtools;
    }, 1000); // we use 1 second delay here
  },
  destroyed() {
    clearInterval(this.interval);
  }

Leave a comment