Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome debugger promises dont resolve while paused?

Maybe I'm not debugging promises right but basically if you stop at break point and run async code it doesnt actually finishes until you resume execution and that's a problem. Debugger allows you to quickly experiment with multiple api methods... but you cant if you resume it

debugger;
//now type the following in console
Promise.resolve().then(()=> console.log('done'));
like image 467
Muhammad Umer Avatar asked Nov 10 '17 05:11

Muhammad Umer


People also ask

What is paused on promise rejection?

Rejecting a promise synchronously has exactly the same behavior as rejecting it asynchronously. The difference you are seeing is Chrome's "pause on uncaught exception" thinking the promise doesn't have a rejection handler attached when it is rejected.

How do I remove debug from pause?

TL;DR Right click in the area where you'd normally set breakpoints, select “never pause here” and you can prevent the debugger from stopping on exceptions or debugger statements.

How do I stop script execution in Chrome?

Open Chrome DevTools. Press Control+Shift+P or Command+Shift+P (Mac) to open the Command Menu. Start typing javascript , select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.


1 Answers

A possible workaround for this is to put debugger in your .then callback as well. This won't work in all situations but it worked for my particular case of debugging node.js scripts before they exit:

  1. insert this into the JS code that you want to debug

    debugger;
    
  2. when the debugger stops, type the following at the console prompt:
    expressionReturningPromise().then( r => {
      console.log('done');
      debugger;
    });
    
  3. resume script execution

The dev tools will then pause on the debugger within the .then callback and you'll have the resolved value of your promise available for examination.

like image 192
electrovir Avatar answered Sep 26 '22 13:09

electrovir