Using window.confirm as a Promise

When writing a modern JavaScript application that uses Promises or async/await, it is sometimes useful to wrap other things in promises so they can more easily be used in a standard way throughout your codebase or in promise chains.

This is especially true if a built-in feature has the same properties of a promise, but is not one. The window.confirm API is one that I wrap a lot in my applications:

function confirmDialog(msg) {
  return new Promise(function (resolve, reject) {
    let confirmed = window.confirm(msg);

    return confirmed ? resolve(true) : reject(false);
  });
 }

And now we can use it just like a normal promise:

confirmDialog('Do you really want to delete this?')
  .then(() => doYourDeleteAction(task.id))
  .catch(err => alert('Unable to delete!'))

Now if you ever want to replace that confirm dialog with some custom version with a fancy UI like a modal window, you can do so much easier – just by updating the confirmDialog function itself.

Chromeless: Switching to Firefox

I have been a long-time Google Chrome user, but have been wanting to switch to Firefox for the past several months, but could not get myself to do it full-time. The interface was a bit dated, and the browser in general didn’t feel faster. I used Firefox Developer Edition for a while which had the newer UI now available in Quantum, but the lack of plugin/add-on support killed my web surfing experience, and I ultimately went back to Chrome.

Then everything changed when the Firefox team announced Firefox Quantum.  I downloaded it to try it out, and was off to the add-on site. The team did a good job ensuring most of the popular add-ons were up-to-date and working with the new changes in Quantum. I was able to quickly find and install the add-ons I needed, and have been using Firefox full-time ever since. It’s a joy to use, and consistently uses significantly less memory than Chrome. It’s my new go-to. Congrats, Firefox team – thanks for the hard work and the great release!