0

Using Google Chrome (Chromium), is it possible to watch/see $.getScript() loading external scripts into your webpage?

Basically, I am dynamically loading many scripts into my webpage based on user preference, and it's causing an issue, I want to check if a particular script is getting inserted or not, and if it is getting inserted, I want to know if it is getting inserted once, or more than once.

oshirowanen
  • 15,297
  • 82
  • 198
  • 350
  • You can debug all JavaScript that executes in the browser, including `$.getScript()`. – Šime Vidas Nov 14 '12 at 15:10
  • Is it possible to see the actual JavaScript inserted in the `Elements` tab of `Google Chrome Developer Tools`? – oshirowanen Nov 14 '12 at 15:12
  • The JavaScript code retrieved via `$.getScript()` is not appended to the DOM, but instead evaluated via `$.globalEval()`. You could set a break point on that latter function to see which scripts get executed. (The source code will be available in String type as the first argument.) – Šime Vidas Nov 14 '12 at 15:34

3 Answers3

1

You can see them in the Network tab of the developer console. Press F12 and go to the Network tab and you'll see all the resources loaded on that page. (You'll need to refresh once you open it.)

Reinstate Monica Cellio
  • 25,975
  • 6
  • 51
  • 67
  • Is it possible to see the actual JavaScript inserted in the `Elements` tab of `Google Chrome Developer Tools`? – oshirowanen Nov 14 '12 at 15:11
  • No - it doesn't show in the elements tab when you use `$.getScript()`. If you want to see it in the head then you need to append it to the head yourself, and not use `$.getScript()`. – Reinstate Monica Cellio Nov 14 '12 at 15:15
  • @Archer `$.getScript` does append ` – Šime Vidas Nov 14 '12 at 15:19
  • @oshirowanen If you want to see the included javascript you can view it from the Network tab by clicking on it. – Reinstate Monica Cellio Nov 14 '12 at 15:22
  • @Archer My mistake. jQuery uses its `$.globalEval()` static function to execute the retrieved JavaScript source code (which in turn uses the built-in `eval()` function, or `execScript()` on IE). – Šime Vidas Nov 14 '12 at 15:32
  • It does add a ` – lapo Jul 09 '13 at 09:07
0

I agree... it's a fail...

In firefox, you can search any declaration with !textToSearch and it will be searched in hidden files loaded by $.getScript() too. This way

In Chrome it don't works... but you can add a Workspace folder and link it to your source. Just right-clicking in server (in sources tab) and "Add folder to workspace"

ton
  • 3,827
  • 1
  • 42
  • 40
0

Using Google Chrome, is it possible to watch/see $.getScript() loading external scripts into your webpage?

Yes, as has been said, you press F12 to access the Developer console and go the the Network Tab.

The files which are inside the red rectangle were loaded with $.getScript()

Network tab in Chrome

João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109