0

I tried to access the DOM for a webpage but I cannot do DOM maniplulation by external javascript codes, (addon or chromium extension) This code works on console page when webpage is open, but does not work as a extension. Could you please help me work this code as a extension

document.getElementById('fb').remove() document.getElementsByTagName('twr-comments')[0].remove() console.log("WORKED!"); console.log('DOM fully loaded and parsed');

1 Answers1

0

The code which you shown will work well but I think you missed to include your .js file in content_scripts block of manifest.json

DharmanBot
  • 1,066
  • 2
  • 6
  • 10
Kishan Vaishnani
  • 234
  • 1
  • 12
  • Thanks for your answer, yes I did include the file in manifest.json. I got an error 'cannot remove() null' – herbertclark Apr 24 '22 at 10:18
  • I think your code is run before render your HTML on browser in that case this will happen sure. Please refer few notes from https://stackoverflow.com/questions/5113318/in-a-chrome-extension-content-script-must-i-wait-for-document-ready-before-proc – Kishan Vaishnani Apr 24 '22 at 10:23
  • 1
    I indeed followed the steps to add setTimeout(function() { document.QuerySelector('#comments'); },5000); But didnt work :(. But the code is working on console. No luck – herbertclark Apr 24 '22 at 11:29
  • If possible can you please provide function OR few more line of code that help me to understand – Kishan Vaishnani Apr 24 '22 at 11:35