0

I'm writing a script loader Chrome extension that will augment the console to allow users to load in scripts from external urls. My core function works something like this:

__('jquery', 'underscore.js', 'backbone.js', function() {
  $('body').append($('<p>').html('I can use jQuery now!'));
});

What I'm wondering is basically what order Chrome content scripts get loaded into the document and if they can be accessed by external scripts? Would it be possible, for example, to call the same code above from the document itself, rather than from the console, or will the script be executed prior to the insertion and execution of my Chrome extension's content script?

wvandaal
  • 4,265
  • 2
  • 16
  • 27
  • Should be fairly easy to test – PeeHaa May 15 '14 at 18:41
  • @PeeHaa no doubt, but I have yet to begin designing the extension part of this project, the standalone script I have at the moment just functions as a script loader. Depending on the answer to the question, I may need to alter the structure of my extension. – wvandaal May 15 '14 at 18:42
  • Have you looked at [`chrome.devtools.inspectedWindow` API](https://developer.chrome.com/extensions/devtools_inspectedWindow), since you're augmenting the console? – Xan May 15 '14 at 18:44
  • Otherwise, take a look at this question: http://stackoverflow.com/questions/9515704/building-a-chrome-extension-inject-code-in-a-page-using-a-content-script – Xan May 15 '14 at 18:45
  • @Xan I understand the basics surrounding the *isolated execution environment* of content scripts. My approach is the recommended method in your linked SO question, namely injecting the content script into the document head. What I'm unclear of is whether this injection will take place before or after any other scripts are executed. Any thoughts on that? – wvandaal May 15 '14 at 18:52
  • I assume that would depend on whether the injecting content script runs before or after the page loads. – Teepeemm May 15 '14 at 22:17
  • @Teepeemm that's what I was wondering about, if anyone knew what the execution order was – wvandaal May 15 '14 at 22:33
  • Look at https://developer.chrome.com/extensions/content_scripts and find the manifest entry for "run_at". – Teepeemm May 15 '14 at 23:39
  • @Teepeemm thank you, that answers my question perfectly! Feel free to type your comment up in an answer and I'll gladly accept it – wvandaal May 15 '14 at 23:45

0 Answers0