5.4. Committing a transaction

The steps to commit a transaction are as follows. This algorithm takes one argument, the transaction to commit.

  1. All the changes made to the database by transaction are written to the database.

  2. If an error occurs while writing the changes to the database, abort the transaction by following the steps to abort a transaction with transaction and an appropriate for the error, for example “[QuotaExceededError](https://www.w3.org/TR/WebIDL-1/#quotaexceedederror)“ or “[UnknownError](https://www.w3.org/TR/WebIDL-1/#unknownerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  3. Queue a task to run these steps:

    1. If transaction is an upgrade transaction, set the database‘s upgrade transaction to null.

    2. Fire an event named complete at transaction.

      Even if an exception is thrown from one of the event handlers of this event, the transaction is still committed since writing the database changes happens before the event takes places. Only after the transaction has been successfully written is the “complete“ event fired.

    3. If transaction is an upgrade transaction, then let request be the request associated with transaction and set request’s transaction to null.