2

Inside the catch of a promise

.catch((message) => {
        console.log(message)
        var newUrl = url
        chrome.tabs.create({url: newUrl}, function(response) {
            console.log(response.status)
            status = 'loading'
            while (status == 'loading') {
                setTimeout(function() {
                    console.log(response.status)
                    status = response.status
                }, 3000)
            }
        })
    })

I'm trying to write the catch in the way that it will open up a new page, wait for it to finish loading, then grab the new cookies

I feel like Im taking crazy pills as this seems super straight forward. However its never printing out response.status

I want it to wait to check response.status every 3 seconds and once the page has loaded it will end the loop.

What am I doing wrong?

Morgan Allen
  • 3,291
  • 8
  • 62
  • 86

1 Answers1

3

The way You've wrote it you've made an infinite loop, which will put tons of setTimeouts on browser's event queue.

setTimeout also put's code there, but it puts it with "3sec plus" delay note.

In practice you tell your browser - set infinite timeouts for me, and after it's finished, please do console.log after 3 seconds. This won't happen.

You should probably use setInterval instead

pbialy
  • 1,025
  • 14
  • 26