0

What I want to do

Log all chat messages on YouTube Live Chat onto console. (Forgive me this, as I am just in the first step.)

What I'm doing

Using MutationObserver to catch changes to a mount point (const point). Here's my code so far.

How I'm testing

I copy and paste the above code to the console after loading a YouTube video with chat messages. (Just for reference, I'm testing on this video)

What I need help with

The code can't find the element I'm using as const point and returns null. However, if I search for the element using my browser inspector it is there. Furthermore, running the code again after having searched for it in inspector gives me my desired result. I want to know what is causing this phenomenon.

deeeeekun
  • 165
  • 8
  • The page is dynamically loaded so when you run your code the element isn't there yet. You could use a timeout of X seconds before executing your code. – iamdlm Sep 01 '21 at 08:42
  • @iamdim I jump forward through the video and only paste my code to the console after I have seen the first few chat messages loaded, though – deeeeekun Sep 01 '21 at 18:48

1 Answers1

0

YouTube's live chat is inside an iFrame so I had to query the selector through the iFrame. Details can be found in the answers to this question.

deeeeekun
  • 165
  • 8