In theory, if I set run_at, the .js that I use to select an element on the page should fire after the page is completely loaded. But it doesn't appear to be the case.
In my content.js, I have
"content_scripts": [
{
"js": ["extensions/jquery-2.2.2.min.js", "content.js"],
"run_at": "document_idle"
}
]
In my content.js, I simply have:
alert("alert");
console.log("hello");
var fullname2 = $('#topcard').find('.profile-info').find('h1').text();
console.log(fullname2);
Both the alert and the first console.log works. The second console log doesn't log anything, because the selector failed to select anything. I know this because if I add a setTimeout for the content.js code block, and wait for 2 seconds, the second console log shows the fullname2 correctly.
Any idea why content.js is apparently firing before the page is fully loaded, such that the selector failed to find anything?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…