Wait for chrome.tabs.update tab to finish loading -


i'm trying work on chrome extension , trying clean of code relying on sendmessage. callback function activates before page has finished loading in case of new tab, nobody receives , in case of existing tab page being moved getting message (but isn't want). i've looked other people asking problem new tabs , there wasn't clear answer, best suggestion i've seen create global variable , create listener tab loads , compare against global variable.

so question is, there way wait in callback function until page has loaded, or create array of js objects contain tab i'm waiting on , information want send tab.

for reference here relevant code in background javascript file.

   chrome.tabs.sendmessage(tab.id, {info: "info"}, function(response)      {      //this line isn't used when navigating without changing tabs      chrome.tabs.create({url: response.info.linkurl}, function(tab1)      {        chrome.tabs.update(tab1.id, {url: response.info.linkurl}, function(tab2)        {          chrome.tabs.sendmessage(tab2.id, {info: "more info"});        });      });    }); 

otherwise able confirm of tab side code works, once sendmessage delayed enough me see own eyes. code able consistently make past validation on page being navigated away from, confirmed checking document.url.

you can try injecting second content script instead of message. execute in same context other script.

something along lines of

chrome.tabs.executescript(tab2.id,    {code: 'showinfo("more info);', runat: 'document_idle'} ); 

where showinfo same message handler.

it's bit of hack , i'm not 100% sure load order correct.

other possible solutions more complex.

for example, can make content script report ready , have handler that, instance can register listener onmessage in background waits message specific tab.id, sends "more info" , deregisters or disables itself.

or, potentially switch programmatic injection of content script, let control load order.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -