Automating YouTube Live Chat Messages Using JavaScript

Automating YouTube Live Chat Messages Using JavaScript

YouTube Live Chat is a powerful way to engage with your audience in real time. But what if you want to automate repetitive messages like reminders, timestamps, or announcements? With a simple JavaScript snippet, you can automate text input and sending in YouTube Live Chat directly from the browser console.

⚠️ Use this responsibly. Automation should support moderation, accessibility, or productivity — not spam.

The Idea

The script below:

  • Finds the YouTube live chat input box

  • Inserts a dynamic message with the current date and time

  • Triggers the input event

  • Clicks the Send button automatically

  • Repeats every 3 seconds

  • Stops after sending 100 messages

This is useful for:

  • Scheduled reminders (e.g., “Subscribe to the channel”)

  • Posting timestamps during live streams

  • Auto-announcements for rules or links

  • Testing chat-based features

The Script

let count = 0;
const maxCount = 100;

const intervalId = setInterval(() => {
const now = new Date();
const dateTime = now.toLocaleString();

const input = document.querySelector(
'div#input.style-scope.yt-live-chat-text-input-field-renderer'
);

if (!input) {
console.error('Input field not found');
clearInterval(intervalId);
return;
}

input.textContent = `Your message ${dateTime}`;
input.dispatchEvent(new Event('input', { bubbles: true }));

const sendButton = document.querySelector('#send-button button');

if (sendButton) {
sendButton.click();
count++;
console.log(`Message ${count} sent: Your message ${dateTime}`);
} else {
console.error('Send button not found');
}

if (count >= maxCount) {
clearInterval(intervalId);
console.log('Finished sending 100 messages');
}
}, 3000);

How to Use It

  1. Open a YouTube Live stream (your own or where you have chat access)

  2. Press F12 to open Developer Tools

  3. Go to the Console tab

  4. Paste the script and press Enter

You’ll see messages being sent automatically every 3 seconds.

Why This Works

YouTube’s chat input is a contenteditable div, not a normal input field.

So instead of using .value, we use:

  • textContent to insert text

  • dispatchEvent(new Event('input')) to simulate typing

  • A programmatic click on the Send button

This mimics real user interaction closely enough for the UI to respond.

Final Thoughts

Browser automation like this is great for:

  • Learning how DOM events work

  • Building prototypes

  • Improving moderation workflows

  • Understanding real-world UI behavior