0

I'm working on a Chrome extension that needs to automatically add comments to a YouTube video. The extension works by opening a new window and navigating to the YouTube URL. Here's how I open the window:

await chrome.windows.create({
    url,
    focused: false,
    type: "panel",
    state: 'minimized'
});

After that, I attempt to scroll down to the comment section and insert a comment using JavaScript like so:

setTimeout(() => {
    document.body.style.zoom = '0.25';
    document.querySelector('[section-identifier="comment-item-section"]').scrollIntoView();
    setTimeout(() => {
        document.getElementById('placeholder-area').click();
        setTimeout(() => {
            dispatchPaste(document.querySelector('ytd-commentbox #contenteditable-root'), comment_data);
            setTimeout(() => {
                document.getElementsByClassName('yt-spec-button-shape-next yt-spec-button-shape-next--filled yt-spec-button-shape-next--call-to-action')[0].click();
            }, 1000);
        }, 1000);
    }, 1000);
}, 3000);

The issue is that the comment section doesn't seem to load unless the window is focused or maximized manually by the user.

Things I've tried:

Zooming out and scrolling to the bottom programmatically, thinking that the comments section needs to be in the viewport. Programmatically firing focus events to emulate user interaction. Using document.hidden and document.visibilityState to manipulate visibility. None of these have worked so far. So I'll be grateful for any help or ideas! Thanks in advance!

  • Seems like you're asking about how to violate Youtube's terms of service. – Ouroborus Sep 03 '23 at 04:49
  • Check how the site detects its visibility state, then spoof it in [page context](/a/9517879). The likely reason is their use of requestAnimationFrame, which runs only in visible pages, so try overwriting it with setImmediate or setTimeout. – wOxxOm Sep 03 '23 at 05:01

0 Answers0