4

I'm trying to write a small Tampermonkey script that will allow me to navigate between conversation threads in WhatsApp's web interface with keyboard shortcuts. In doing so, I'm trying to figure out how to programmatically "click" on a conversation in the contacts side nav to set it as the active one.

The first thing I tried was going as far down the DOM tree as I could for a contact in the side nav, to <div class="chat">, and called .click() on it from the console. Nothing. Then I tried calling .dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true })) on the element as well. Still nothing. Lastly, I tried both methods above on all of the element's parents until I reached the "top" level for the contact in the side nav. Nothing worked.

Any ideas why WhatsApp's web interface seems impervious to manually fired click events? (I tried other elements on the page as well, text inputs and buttons, and nothing seemed to respond.)

Adil B
  • 14,635
  • 11
  • 60
  • 78
davidlav
  • 636
  • 5
  • 17
  • What URL and *exactly* what browser are you using? That site has no browser interface that I can see. And things like Tampermonkey are useless on most apps. – Brock Adams Jan 20 '18 at 00:39
  • https://web.whatsapp.com/ and I've tried both Firefox 56 and Chrome 63. It's got nothing to do with Tampermonkey at this point, I'm simply trying to click on a `div.chat` element from the console, and that's what I'm unable to do. – davidlav Jan 20 '18 at 00:55
  • I'm not seeing anything with `class="chat"` but also tried to trigger most of the elements for a contact on the side nav without any luck... what a mistery :( – brasofilo May 15 '18 at 16:17

1 Answers1

-2

When you select by class i.e. $('.chat') you will get an array of elements, you need to go to the one that you're looking for, if is the only one then just:

$('.chat')[0].click();

this is, of course, taking for granted that the page is using jQuery

Luis Gonzalez
  • 531
  • 5
  • 16
  • Have you actually gotten it to work on web.whatsapp.com? I know that method would normally work, but it doesn't on that page. – davidlav Jan 19 '18 at 22:09