Hello there i am new to chrome extension programming and to do some practice i am creating a chrome extension which extracts the inner text of h2> from the page in which the user is browsing. although i learned about content scripts and have used it but it is not working i don't know where is the problem. if anyone could help me that would be greatly appreciated.
this is the js code:
document.addEventListener('DOMContentLoaded', function() {
var link = document.getElementById('button');
link.addEventListener('click', function() {
updateresult();
});
});
function updateresult() {
var i;
var x =document.getElementsByTagName("h2");
for(i=0; i< x.length ; i++)
{
document.getElementById("result").innerHTML = (x[i].innerHTML + "\n");
}}
this is the manifest file which i am using :
{
"manifest_version": 2,
"name": "Header Extractor",
"description": "Extension to search header",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"16": "icon.png",
"48": "icon.png",
"128": "icon.png",
"default_popup":"popup.html",
"default_title": "Open And Search headers"
},
"permissions": [
"storage",
"activeTab" ,"tabs"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": [ "popup.js"],
"run_at": "document_end"
}
]
}
You just insert your content scripts too late. You have set “run_at”: “document_end” in manifest.json, while you are listening “DOMContentLoaded” event in content scripts, please be aware “DOMContentLoaded” event fires before “document_end”, so that means your handler would never be executed.
Either setting “run_at”: “document_start” or removing the outer “DOMContentLoaded” listener would solve your problems.
BTW, there are many related questions here http://stackoverflow.com/questions/tagged/google-chrome-extension
Thanks
--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/28e4a0e9-e556-4a4b-aee4-876eb484f5c8%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.