Execute QuerySelector from chrome.executeScript

I am trying to extract the youtube comments from a chrome extension. I am fairly new to extensions and I can't understand why this excerpt is not working the js file is:

chrome.tabs.onActivated.addListener((tab) => {
  var tabId = tab.tabId;
  chrome.tabs.get(tab.tabId, (current_info) => {
    if (current_info.favIconUrl.includes("www.youtube.com")) {
      chrome.tabs.executeScript(tabId, { 
          code: '('+function(){
            return{
                code: document.querySelectorAll('yt-formatted-string[class="style-scope 
ytd-comment-renderer"][ slot="content"][id="content-text"]')
            }
          }+')()'
       }, (res) => {
        console.log(res);
      })
    }
  });
});


Read more here: https://stackoverflow.com/questions/64944980/execute-queryselector-from-chrome-executescript

Content Attribution

This content was originally published by Siddhant Tiwary at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: