Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8325903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:35:27+00:00 2026-06-09T00:35:27+00:00

While debugging some client side javascript today in Firefox, I ran into something that

  • 0

While debugging some client side javascript today in Firefox, I ran into something that I found quite odd and little unnerving. Also, I was unable to duplicate this behavior while debugging the same script with IE / VS2010.

I created a simple example html document to illustrate the anomally I am seeing.

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" type="text/javascript" ></script>
</head>

<body id="main_body">
    <script type="text/javascript">
        $(function () {
            $(".test-trigger").on("click", function () {
                loadStuff();
                console && console.log && console.log("this will probably happen first.");
            });
        });

        function loadStuff() {
            $.get("http://google.com/")
                .fail(function () {
                    console && console.log && console.log("this will probably happen second.");
                });
            }
    </script>
    <button class="test-trigger">test</button>
</body>
</html>

If you load this document into Firefox (I am using version 13.0 with Firebug version 1.10.1 on Windows 7), click test, and view the console tab in Firebug you should notice that the get request fails (cross domain violation that has nothing to do with the point I’m trying to make here), and then you will most likely see:

this will probably happen first.
this will probably happen second.

Now, place breakpoints on lines 13 and 20:

13: console && console.log && console.log("this will probably happen first.");
20: console && console.log && console.log("this will probably happen second.");

If you click test again you will break on line 13 as expected. Now, resume execution. If your experience is like mine, you will not break on line 20. Also if you switch to the console tab you will see the following sequence of log output:

this will probably happen second.
this will probably happen first.

To me, this suggests that the fail handler of the ajax request is being executed in a thread other than that which the click handler is being executed in. I have always been led to believe that all the javascript for a single page will be executed by a single thread in any browser. Am I missing something really obvious here? Thanks for any insight on this observation.

Oh, if I debug the same page running in IE using Visual Studio, both breakpoints are hit as I would expect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:35:29+00:00Added an answer on June 9, 2026 at 12:35 am

    I think it’s safe to assume that the anomaly you’re observing is caused by how Firebug implements breakpoints/works under the hood. I can’t confirm that though. This also happens with FF 14 on OS X.

    Unless jQuery immediately executes your fail() function and surpasses the whole XMLHttpRequest object, then there is a guarantee that the ordering of the statements will be this will probably happen first. then this will probably happen second..

    Given the single threaded nature of JavaScript, functions will be essentially atomic; they will not get interrupted by a callback.

    It seems as though you’re trying to simulate what would happen if the click function takes a while to finish executing after calling loadStuff(). The click function shouldn’t get interrupted by the fail method executing (mind == blown that you found a way to make that happen).

    To take breakpoints out of the equation, here’s a modified version. The rest of the markup is unchanged.

    $(function () {
        $(".test-trigger").on("click", function () {
            loadStuff();
            for (var i = 0; i < 1000000000; i++)
            {
                //block for some interesting calculation or something
            }
            console && console.log && console.log("this will probably happen first.");
        });
    });
    
    function loadStuff() {
        $.get("http://google.com/")
            .fail(function () {
                console && console.log && console.log("this will probably happen second.");
            });
        }
    

    The click function clearly takes a long time to execute, after calling loadStuff(), but the console will still reflect the correct order of the log statements here. Also worth noting, if you insert the same breakpoints, the ordering will be invalid, like the original example.

    I’d file an issue for this with Firebug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When debugging some web-service client code today (in Java, with jax-ws) I ran across
While debugging a client app that uses a Google backend, I have added some
I found something strange while debugging some code. Apparently, >>> (0-6) is -6 False
While debugging javascript written by someone else, I came across some code that I've
I ran into this head scratcher while debugging a transactional query block. For some
I noticed while debugging some Javascript that an extra argument that I was passing
I've found that on some occasions I can edit the source while debugging. Are
I have some debugging code that if executed while running with GBD attached should
While debugging Java code that uses reflection in Eclipse, some times I need to
Several times while debugging a VB.Net program I have found that continuation lines are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.