Home > Mobile >  React - How to add listener whether the function do if user open web browser's console
React - How to add listener whether the function do if user open web browser's console

Time:04-09

I'm working on React, but I want to execute the function only if the user open the web browser's console. I don't know that should I use the window.addEventListener or something else that like useEffect() that has a empty dependency array but run when user open web browser's console instead.

Is the React has an event listener that detect if user open the web browser's console.

CodePudding user response:

Sir, There a simple way of doing this would be to check when the window is resized. Since you can't check the console without resizing the page, it would work (this works with both horizontal and vertical dev tools)

window.addEventListener('resize', function () {
  console.log('You resized this window or accessed the console.');
});

CodePudding user response:

If an event listener is added to an EventTarget from inside another listener — that is, during the processing of the event — that event will not trigger the new listener. However, the new listener may be triggered during a later stage of event flow, such as during the bubbling phase.

addEventListener(type, listener);
addEventListener(type, listener, options);
addEventListener(type, listener, useCapture);
  • Related