'DOM manipulation not working as a firefox addon or chrome extension but works on console [duplicate]

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');



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DharmanBot