javascript - Trying to use a Chrome Extension to fetch certain pieces of text from a webpage -


this first attempt @ building chrome extension , i'm trying learn how building extension tracks television series watch. extension supposed to, among other things, fetch metadata series , display on html page. whenever try fetch title of series using tag or class, etc. (determined using chrome's inspect element function) end "undefined". have tried using .innertext same happens.

here javascript using:

$(document).ready(function(){ document.getelementbyid("subscribe").addeventlistener("click",myfunction); function myfunction() {    chrome.tabs.query({active: true, currentwindow: true}, function(tabs) {         chrome.tabs.sendmessage(tabs[0].id, {subscribe: "yes"}, function(response) {             var bkg = chrome.extension.getbackgroundpage();             bkg.console.log(response.confirm);             bkg.console.log(response.atitle); \\i wrote check data fetched, gives undefined             document.getelementbyid("antitle").innerhtml=response.atitle;         });     }); } 

});

here content script using:

chrome.runtime.onmessage.addlistener( function(request, sender, sendresponse){     if (request.subscribe=="yes"){         console.log("subscription: " + request.subscribe);         sendresponse({             confirm: "request received",             atitle: document.getelementsbytagname("h1").innertext \\this title on webpage tried         })     }     else {         console.log("subscription request not received");     } } 

)


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -