I have been trying to create a GeckoView based web extension for downloading images on my facebook mobile feed. So as a first run, I used Inspect> console in google chrome to test a simple script to detect all images and make the border red:
var imgs=document.getElementsByTagName("img");
for (i=0;i<imgs.length;i++)
{
imgs[i].style.border="3px solid red";
}
The above lines of code work perfectly well in google chrome console for a number of websites (including facebook). However when I package the JS code as a content script for geckoview web extension, it simply fails to work ! Here are all the tricks I have tried so far:
Making sure that the content_script is loaded AFTER the document by including:
"content_scripts": [{ "run_at": document_end, "js": ["myscript.js"], "matches": ["<all_urls>"], "match_about_blank": true, "all_frames": true }]
Also tried:
"run_at": document_idle.
Making sure that 'x-ray' vision is off by using
document.wrappedJSObject.getElementsByTagName("img")
Unregistering and re-registering web extension.
None of this worked. Interestingly, the web extension works on all other websites except facebook ! So I am suspecting I have one of the two problems:
- Facebook has done a really great job hiding their DOM !
- GeckoView cannot access DOM for "dynamically generated" image elements.
Any help would be appreciated :)