2

I'm using this javascript function to scroll down webpages by code:

window.scrollBy({ top: 300, behavior: "smooth" });"

This code works fine with my browser on many webpages.

Now I'm on web.whatsapp.com, and the function doesn't do anything.

I can scroll using the arrow keys on the keyboard and by using the mouse wheel, but not using this code.

What could I investigate what goes wrong here?

Thank you.

tmighty
  • 10,734
  • 21
  • 104
  • 218

1 Answers1

3

By the time of this writing, web.whatsapp.com does not have a scrollable window. However, the scrollBy function can also be used to scroll other containers.

Try this to scroll the chat list:

document.getElementById('pane-side').scrollBy({top: 100})

The current obfuscated class for the container wrapping a chat's messages is _2nmDZ:

document.querySelector('._2nmDZ').scrollBy({top: 100})

Note that both the side panel ID and the chat panel class most certainly will change in the future.

Barthy
  • 3,151
  • 1
  • 25
  • 42
  • Very valuable, thank you. But I want to scroll the "Messages" window which appears when you click one of your contacts. – tmighty Apr 17 '19 at 00:30
  • Well it's the same principle. Find the scrolling `div` and scroll it :) – Barthy Apr 17 '19 at 00:31
  • @tmighty See the update for how to scroll the chat area. In order to find the correct div you need to find the container that wraps the scrollable content and for example has `overflow-x: hidden; overflow-y: scroll;` style properties. – Barthy Apr 17 '19 at 00:38
  • @tmighty or have a look at these: [find first scrollable parent](https://stackoverflow.com/questions/35939886/find-first-scrollable-parent) and [scollparent.js](https://github.com/olahol/scrollparent.js) – Barthy Apr 17 '19 at 00:39