1

When you add a script tag with an src field pointing to a javascript file, the browser gets it and executes it.

What I am wondering is how does this process work. Does the file get fetched and then somehow eval()'ed? Is it a mystical process that happens outside of the scope we have access? Or can we monitor/interfere this?

To explain what I want to achieve: I want to give access to third parties to customize their page on my site by linking to their own javascript files. I want to be able to centrally log any errors that prevent those external scripts from loading (i.e. their server is down, parsing errors, whatever). Is it possible?

Thanks!

  • Obviously there are other ways to solve this such as hosting their scripts on my server and giving them a way to update them, but I 'm interested in knowing if my current approach is possible.
7
  • Greasemonkey is Javascript and runs inside the chrome (sorta, I think). It's possible, you just need to look into probably how add-ons work. Commented Dec 12, 2012 at 1:58
  • You might take a look at this answer: stackoverflow.com/questions/12450755/… At least there's a few resources for you to look at. You can see a lot in Firefox and Chrome just by right-clicking and digging around the Console/Inspectors and whatnot. Commented Dec 12, 2012 at 2:16
  • @JaredFarrish: Thanks but theses are for extensions and extensions are allowed to do things "normal" javascript can't do/access. Commented Dec 12, 2012 at 2:20
  • In that context, I was talking about Extensions and other ways of running code on the browser. If you want to see how a browser might request, receive, load and parse, you might be surprised at some of those view-source:chrome:// files. Take a look at this file in Chrome: view-source:chrome://resources/js/util.js Copy and paste that into the address bar. You're looking at the Chromium Javascript "source". Wacky. Commented Dec 12, 2012 at 2:24
  • 1
    Yeah, that answer was where I cataloged what I figured out exploring around. I never had any idea. Try this: view-source:chrome://sync-internals/ Starting on line 123 (at least on mine), check out that list of internal resources and other browser scripts. Commented Dec 12, 2012 at 2:31

2 Answers 2

3

You can look at specific implementation in Firefox & Chromium sources with some grep magic, for your specific scenario I'd asynchronously subload those by inserting script tags on the fly and listening to global errors/events (eg window.onerror) from there.

Sign up to request clarification or add additional context in comments.

Comments

0

It loads the java script file while loading the page and stores that script in its cache. If you load page another time then it will get that js from the cache.

1 Comment

Thanks, but that doesn't answer the question of how to get the error though ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.