I am currently working on a chrome extension, and the source code is available on Github . The goal is to add custom Javascript to your web pages.
Currently, I store each custom Javascript Inject in localStorage and is called from them. I set run_at to document_start .
I use this to get saved injections from a background script:
chrome.extension.sendMessage({method:"get_injects"},function(injects){ for(index in injects){ if(/^items\./.test(index)){ itemJSON = injects[index]; //if(window.location.host.toString().indexOf(itemJSON.url)){ if(window.location.host.toString().match(itemJSON.url + '$')){ var js = itemJSON.js.toString(); eval(js); } } } });
Problem
I want to run Inject scripts exactly before loading the document. But using the method presented, the control will pass chrome.extension.sendMessage and will not wait to receive an injects response. Thus, eval(js); will be executed in the middle of the page load. How can I solve this problem so that I can embed it before the page loads?
source share