Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    FF and Chrome won't allow me to stop unresponsive script

    FF and Chrome won't allow me to stop an unresponsive script, that is, a popup doesn't appear that gives me the choice. I'm fairly new at JS, but understand the basics, and there's a simple JS file I'm working on, but when I edit it and refresh my page in Firefox or Google, I just get the Mac colored pinwheel and the popup that would normally appear, never appears. Seems that now Firefox has finally displayed the popup but not Chrome. FF did it after about 4 or 5 minutes, which means that, at this rate I'll never get my script debugged. Is there some way to stop an unresponsive script sooner in FF, or to even stop it at all in Chrome?
    Thanks.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,251
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    Change your browser settings? Use the F12 key to summon the error console.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    chrome js script debug problem

    I'm on a Mac so f12 only raises the volume. I can hit "fn" and f12 and get the developer tools, but that's not the problem. When I have the dev tools open and I refresh a page with an unresponsive script, I never get the chance to stop the script from running and then to debug it. No popup ever appears so I can stop the script and start to debug. I'd like to be able to use the Chrome tools, but I can't. Get it?
    Thanks.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by ricksta4591 View Post
    When I have the dev tools open and I refresh a page with an unresponsive script, I never get the chance to stop the script from running and then to debug it.
    Set breakpoints BEFORE you run the script.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    And if the unresponsive script starts up when the page first runs, then simply temporarily put a return right after the start of the script. Run that version, which will then give you a chance to set the breakpoint, and then just comment out the return before reloading the page.

    Example:
    Code:
    <script type="text/javascript">
    (
      function( ) /* master anonymous function */
      {
          return; // added ...comment out after setting breakpoints
          while ( true ) { /* infinite loop */ }
          ...
      }
    )();
    </script>
    This gives you a chance to set a breakpoint on the while and/or on code inside the infinite loop (which presumably wasn't supposed to be infinite).

    Lots of other variations on this theme.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    ricksta4591 (03-22-2013)

  • #6
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I can't even type into the javascript window. I'm locked out because I can't do anything without first stopping the script from running. So I can't use the developer tool for debugging or anything. Chrome won't allow me to stop the script so I can debug.
    Thanks.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,191
    Thanks
    80
    Thanked 4,562 Times in 4,526 Posts
    Sorry, but I don't believe you.

    There *IS* a way to make it work. You just need to find it.

    Again: Just put a return (or introduce a JavaScript error, for that matter) just before the code where it goes into the infinite loop. Then follow what I described, above.

    If you don't know where to put the return, then show your code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    html code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Logic Errors</title>
    </head>
    <body>
    <h1>Logic Errors</h1>
    <p><a href="logic.html">This page</a> loads a script that contains logic errors, including an infinite loop!</p>
    <p>This is an <a href="http://www.example.com/" class="example">example</a>, but this <a href="http://www.sitepoint.com/">is not</a>.</p>
    <script type="text/javascript" src="logic.js"></script>
    </body>
    </html>

    JS code:
    // This script contains three logic errors
    var MyScript = {
    init: function()
    {
    var links = document.getElementsByTagName("a");
    var exampleLinks = [];
    for (var i = 0; i < links.length; i++)
    {
    if (links[i].className = "Example")
    {
    links[i].addEventListener("click", MyScript.doSomething, false);
    exampleLinks[exampleLinks.length] = links[i];
    i--;
    }
    }
    },
    doSomething: function(event)
    {
    alert("Hold onto your \"hat\"!");
    }
    };

    MyScript.init();

    As you can see, this code is part of the course in JS I'm taking. It's supposed to have errors. When I open the html in Chrome, I can't see the script in the inspector. Chrome version is 25.0.1364.172 Can you see the web developer tools inspector?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •