0

Consider this code:

const myPromise = new Promise((resolve, reject ) => {
    setTimeout(() => { 
        console.log("log1!")
        resolve({
            name: 'whatever',
            age: 17
        })
    }, 3000)
})

myPromise.then((data) => data.age) // breakpoint here

I want to log data in the browser. Breakpoint stops when the promise fires but not after it resolves so cannot check the value of data. I tried "pretty print" icon in the browser {} but does not break the line of the promise .then so that I cannot add a breakpoint and check the result.

Is there any way to log data in the browser?

rustyBucketBay
  • 4,320
  • 3
  • 17
  • 47
  • 1
    Do you just mean this?: `myPromise.then((data) => console.log(data))` It's not really clear to me what you're asking, the code shown demonstrates how to log something to the console and then asks how to log something else to the console. Can you clarify the problem? – David Apr 18 '23 at 12:07
  • 1
    I cannot modify the code in the browser so I cannot add a `console.log` – rustyBucketBay Apr 18 '23 at 12:11
  • You literally _can_ edit the code in the debugger though. – deceze Apr 18 '23 at 12:13
  • in the debugger? where? May I edit the script in the browser? I am not in the debugger, the problem states its code already served to the browser. – rustyBucketBay Apr 18 '23 at 12:15
  • In the Sources tab, where you have the code and can set breakpoints. Just type. – deceze Apr 18 '23 at 12:17
  • Breakpoint stops when the promise fires but not after it resolves so cannot check the value of data – rustyBucketBay Apr 18 '23 at 12:20

0 Answers0