how to invoke a function only on browser close

Viewed 148

I have a situation where I want to clear out the user Front End session only when the browser is closed if there are some tabs of the same system opened and one of them closed I dont want to do anything, If there is a page refresh i dont want to do anything either, just on browser close or all tabs close, let me show you my code

App.vue

    async created() {
        window.addEventListener("beforeunload", this.handler);
    }
methods:{
    handler(){// eslint-disable-line no-unused-vars
    console.log("here");
      sessionMixin.methods.clearSession();
      return null;
    }
  }

while this does work, but the problem is it is being called on every refresh and tab close which logs the user out and i dont want that,is there a way maybe to differentiate between page refresh/tab close/browser close? or anything else?

0 Answers
Related