Dynamically Loaded Scripts

View: New views
6 Messages — Rating Filter:   Alert me  

Dynamically Loaded Scripts

by Gregory Hellings :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using Firebug to debug some JavaScript files that I've written.
However, a number of the scripts are dynamically loaded by my
original, static JavaScript files only if the user selects portions of
the page which require them.  This is using the jQuery.getScript()
method to do the fetch and execute.

In Firebug's list of scripts, I see all of my statically linked
scripts, and all of my eval'd JSON calls to the server, but I don't
see the dynamically loaded scripts that came across with the jQuery
call.  Am I missing some setting in Firebug ("Show Static, eval and
event Scripts" is selected), or are they not being displayed for some
other reason that I'm missing?

--Greg

--

You received this message because you are subscribed to the Google Groups "Firebug" group.
To post to this group, send email to firebug@....
To unsubscribe from this group, send email to firebug+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/firebug?hl=en.



Re: Dynamically Loaded Scripts

by John J Barton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Oct 29, 10:16 am, Gregory Hellings <greg.helli...@...> wrote:
> I'm using Firebug to debug some JavaScript files that I've written.
> However, a number of the scripts are dynamically loaded by my
> original, static JavaScript files only if the user selects portions of
> the page which require them.  This is using the jQuery.getScript()
> method to do the fetch and execute.

To help I'd need to know that this function does under the covers.

If they use eval() or script tag injection, then you should see the
source. If they use new Function(), we don't support for that yet.
There are other approaches, some work, some don't. (I plan replace the
current hack with real code in Firebug 1.6).

jjb

>
> In Firebug's list of scripts, I see all of my statically linked
> scripts, and all of my eval'd JSON calls to the server, but I don't
> see the dynamically loaded scripts that came across with the jQuery
> call.  Am I missing some setting in Firebug ("Show Static, eval and
> event Scripts" is selected), or are they not being displayed for some
> other reason that I'm missing?
>
> --Greg

--

You received this message because you are subscribed to the Google Groups "Firebug" group.
To post to this group, send email to firebug@....
To unsubscribe from this group, send email to firebug+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/firebug?hl=en.



Re: Dynamically Loaded Scripts

by Gregory Hellings :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John,

On Thu, Oct 29, 2009 at 3:59 PM, John J Barton
<johnjbarton@...> wrote:

>
>
> On Oct 29, 10:16 am, Gregory Hellings <greg.helli...@...> wrote:
> > I'm using Firebug to debug some JavaScript files that I've written.
> > However, a number of the scripts are dynamically loaded by my
> > original, static JavaScript files only if the user selects portions of
> > the page which require them.  This is using the jQuery.getScript()
> > method to do the fetch and execute.
>
> To help I'd need to know that this function does under the covers.

Without trying to replicate too much of their code and at risk of
showing you the wrong parts, it looks like it boils down to the
following primary lines:
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = s.url;
script.onload = script.onreadystatechange = function(){
       // Handle memory leak in IE
       script.onload = script.onreadystatechange = null;
       head.removeChild( script );
                        }
head.appendChild(script);

Obviously, I greatly simplified that, but it appears to me to be the
main method calls during a call to jQuery.getScript().  In summary, in
case I butchered it too badly, it creates a script tag, appends it to
the header, points its source to the requested script and, on load,
removes it from the header.  The last behavior - removing it from the
header - would seem, to me, to be the reason that I can't find the
script to put breakpoints and traces on.

--Greg

--

You received this message because you are subscribed to the Google Groups "Firebug" group.
To post to this group, send email to firebug@....
To unsubscribe from this group, send email to firebug+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/firebug?hl=en.



Re: Dynamically Loaded Scripts

by John J Barton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Oct 29, 2:22 pm, Greg Hellings <greg.helli...@...> wrote:

> John,
>
> On Thu, Oct 29, 2009 at 3:59 PM, John J Barton
>
> <johnjbar...@...> wrote:
>
> > On Oct 29, 10:16 am, Gregory Hellings <greg.helli...@...> wrote:
> > > I'm using Firebug to debug some JavaScript files that I've written.
> > > However, a number of the scripts are dynamically loaded by my
> > > original, static JavaScript files only if the user selects portions of
> > > the page which require them.  This is using the jQuery.getScript()
> > > method to do the fetch and execute.
>
> > To help I'd need to know that this function does under the covers.
>
> Without trying to replicate too much of their code and at risk of
> showing you the wrong parts, it looks like it boils down to the
> following primary lines:
> var head = document.getElementsByTagName("head")[0];
> var script = document.createElement("script");
> script.src = s.url;
> script.onload = script.onreadystatechange = function(){
>        // Handle memory leak in IE
>        script.onload = script.onreadystatechange = null;
>        head.removeChild( script );
>                         }
> head.appendChild(script);
>
> Obviously, I greatly simplified that, but it appears to me to be the
> main method calls during a call to jQuery.getScript().  In summary, in
> case I butchered it too badly, it creates a script tag, appends it to
> the header, points its source to the requested script and, on load,
> removes it from the header.  The last behavior - removing it from the
> header - would seem, to me, to be the reason that I can't find the
> script to put breakpoints and traces on.

If you are using a recent version of Firebug, this removeChild() will
not cause a problem. Try Firebug 1.5xb1, http://getfirebug.com/releases/firebug/1.5X.
Let us know.
jjb

>
> --Greg

--

You received this message because you are subscribed to the Google Groups "Firebug" group.
To post to this group, send email to firebug@....
To unsubscribe from this group, send email to firebug+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/firebug?hl=en.



Re: Dynamically Loaded Scripts

by Gregory Hellings :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John

On Thu, Oct 29, 2009 at 4:28 PM, John J Barton
<johnjbarton@...> wrote:

>
>
> On Oct 29, 2:22 pm, Greg Hellings <greg.helli...@...> wrote:
>> John,
>>
>> On Thu, Oct 29, 2009 at 3:59 PM, John J Barton
>>
>> <johnjbar...@...> wrote:
>>
>> > On Oct 29, 10:16 am, Gregory Hellings <greg.helli...@...> wrote:
>> > > I'm using Firebug to debug some JavaScript files that I've written.
>> > > However, a number of the scripts are dynamically loaded by my
>> > > original, static JavaScript files only if the user selects portions of
>> > > the page which require them.  This is using the jQuery.getScript()
>> > > method to do the fetch and execute.
>>
>> > To help I'd need to know that this function does under the covers.
>>
>> Without trying to replicate too much of their code and at risk of
>> showing you the wrong parts, it looks like it boils down to the
>> following primary lines:
>> var head = document.getElementsByTagName("head")[0];
>> var script = document.createElement("script");
>> script.src = s.url;
>> script.onload = script.onreadystatechange = function(){
>>        // Handle memory leak in IE
>>        script.onload = script.onreadystatechange = null;
>>        head.removeChild( script );
>>                         }
>> head.appendChild(script);
>>
>> Obviously, I greatly simplified that, but it appears to me to be the
>> main method calls during a call to jQuery.getScript().  In summary, in
>> case I butchered it too badly, it creates a script tag, appends it to
>> the header, points its source to the requested script and, on load,
>> removes it from the header.  The last behavior - removing it from the
>> header - would seem, to me, to be the reason that I can't find the
>> script to put breakpoints and traces on.
>
> If you are using a recent version of Firebug, this removeChild() will
> not cause a problem. Try Firebug 1.5xb1, http://getfirebug.com/releases/firebug/1.5X.
> Let us know.
> jjb

I was running 1.4.3.  I updated to 1.5xb1.  Now I see the part of the
script.  My script creates an object which has a handful of methods in
it, and I can see each of the function definitions and their lines,
but any breakpoints I set in them are not giving me actual code
breaks, and I can't see the original code of the object.  The name
under which I found them is also listed as <current URL>/event rather
than the address of the script that was loaded at that event, which I
understand from a technical standpoint, but it makes it tough to
identify the script in question.

It's a step in the right direction over 1.4.3!  Thanks.

--Greg

>
>>
>> --Greg
>
> --
>
> You received this message because you are subscribed to the Google Groups "Firebug" group.
> To post to this group, send email to firebug@....
> To unsubscribe from this group, send email to firebug+unsubscribe@....
> For more options, visit this group at http://groups.google.com/group/firebug?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups "Firebug" group.
To post to this group, send email to firebug@....
To unsubscribe from this group, send email to firebug+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/firebug?hl=en.



Re: Dynamically Loaded Scripts

by John J Barton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Oct 29, 2:37 pm, Greg Hellings <greg.helli...@...> wrote:

> John
>
> On Thu, Oct 29, 2009 at 4:28 PM, John J Barton
>
>
>
> <johnjbar...@...> wrote:
>
> > On Oct 29, 2:22 pm, Greg Hellings <greg.helli...@...> wrote:
> >> John,
>
> >> On Thu, Oct 29, 2009 at 3:59 PM, John J Barton
>
> >> <johnjbar...@...> wrote:
>
> >> > On Oct 29, 10:16 am, Gregory Hellings <greg.helli...@...> wrote:
> >> > > I'm using Firebug to debug some JavaScript files that I've written.
> >> > > However, a number of the scripts are dynamically loaded by my
> >> > > original, static JavaScript files only if the user selects portions of
> >> > > the page which require them.  This is using the jQuery.getScript()
> >> > > method to do the fetch and execute.
>
> >> > To help I'd need to know that this function does under the covers.
>
> >> Without trying to replicate too much of their code and at risk of
> >> showing you the wrong parts, it looks like it boils down to the
> >> following primary lines:
> >> var head = document.getElementsByTagName("head")[0];
> >> var script = document.createElement("script");
> >> script.src = s.url;
> >> script.onload = script.onreadystatechange = function(){
> >>        // Handle memory leak in IE
> >>        script.onload = script.onreadystatechange = null;
> >>        head.removeChild( script );
> >>                         }
> >> head.appendChild(script);
>
> >> Obviously, I greatly simplified that, but it appears to me to be the
> >> main method calls during a call to jQuery.getScript().  In summary, in
> >> case I butchered it too badly, it creates a script tag, appends it to
> >> the header, points its source to the requested script and, on load,
> >> removes it from the header.  The last behavior - removing it from the
> >> header - would seem, to me, to be the reason that I can't find the
> >> script to put breakpoints and traces on.
>
> > If you are using a recent version of Firebug, this removeChild() will
> > not cause a problem. Try Firebug 1.5xb1,http://getfirebug.com/releases/firebug/1.5X.
> > Let us know.
> > jjb
>
> I was running 1.4.3.  I updated to 1.5xb1.  Now I see the part of the
> script.  My script creates an object which has a handful of methods in
> it, and I can see each of the function definitions and their lines,
> but any breakpoints I set in them are not giving me actual code
> breaks, and I can't see the original code of the object.  

I don't understand "original code of the object".

> The name
> under which I found them is also listed as <current URL>/event rather
> than the address of the script that was loaded at that event, which I
> understand from a technical standpoint, but it makes it tough to
> identify the script in question.

The code you posted should not appear under "/event"; it should appear
under the url of the src= attribute on the script tag. If you create a
test case and post it the the issue list,
http://code.google.com/p/fbug/issues/list, I'll fix it.

>
> It's a step in the right direction over 1.4.3!  Thanks.
>
> --Greg
>
>
>
> >> --Greg
>
> > --
>
> > You received this message because you are subscribed to the Google Groups "Firebug" group.
> > To post to this group, send email to firebug@....
> > To unsubscribe from this group, send email to firebug+unsubscribe@....
> > For more options, visit this group athttp://groups.google.com/group/firebug?hl=en.
>
>

--

You received this message because you are subscribed to the Google Groups "Firebug" group.
To post to this group, send email to firebug@....
To unsubscribe from this group, send email to firebug+unsubscribe@....
For more options, visit this group at http://groups.google.com/group/firebug?hl=en.