I am trying to make a chrome extension for Google Meet, in which when I press the space bar, the mic should turn on and vice-versa. This is my code...
//Listening to key events to trigger suitable event
document.addEventListener('keypress', (event) => {
items = document.getElementsByTagName("div");
if (event.keyCode == 32) {
for (i = 0; i < items.length; i++) {
if (items[i].hasAttribute("aria-label")) {
if (items[i].getAttribute("aria-label")
.includes("microphone")) {
items[i].click();
}
}
}
}
});
When I press the space bar, the microphone does not get affected, on the other hand, if I add an alert, that works perfectly fine. What could be the mistake?
Thanks in advance