How to disable / disable Google Hangout via JS (no jQuery)?

I want to write a Chrome extension that allows you to disable / disable the video call from the browser’s action button and not open the Hangouts tab and do it there, but it looks like their HTML and JS are messed up, so I can’t come up with a decent desire to launch it when it starts in JS console.

I managed to select the button element itself using

el = document.querySelector("[data-tooltip='Unmute microphone']"); 

... but el.click() works, which does nothing. So I tried to set a breakpoint on click, but it just shot me in a huge JS file with a bunch of minified code, so I'm kind of out of ideas.

+6
source share
1 answer

After a few minutes of working with the Chrome developer tools, I decided not to go through the source code using the debugger, but to study the behavior of the button with control points (the Sources panel) and some educated assumptions.

In short, Hangouts can be disabled (un) by triggering the following events in that order:

  • mousedown - To activate a button
  • mouseup - To start the associated click handler
  • mouseout - To remove the focus ring from the button (optional).

To select the target element, I did not use the selector that you provided, because it will not work for the localized (non-English) Hangouts interface. Instead, I aim the CSS class on the microphone icon and select its container (button), "ha-wPy-Xi-f".

Finally, use the MouseEvent constructor (DOM4) and dispatchEvent to switch the microphone in Hangouts:

 var el = document.querySelector('.ha-wPy-Xi-f').parentNode; el.dispatchEvent(new MouseEvent('mousedown')); el.dispatchEvent(new MouseEvent('mouseup')); el.dispatchEvent(new MouseEvent('mouseout')); 
+6
source

Source: https://habr.com/ru/post/947855/


All Articles