I have a problem with my chrome extension, the extension reads an object from the page and displays its contents in popup.js.
To read the object, popup executes injects.js which in turn injects script.js.
So what happens is, when inject.js completes execution the popup.js callback is called and renderData(mydata)
is executed. I don't want this to happen until script.js is executed completely
Popup.js
chrome.tabs.executeScript(null, { file: "inject.js" }, function() {
renderData(mydata);
});
inject.js
var s = document.createElement("script");
s.src = chrome.runtime.getURL("script.js");
(document.head || document.documentElement).appendChild(s);
script.js
var data = {
type: "FROM_PAGE",
text: JSON.stringify(WIO.sessionInfo.context)
};
window.postMessage(data, "*");