A DOMRequest object represents an ongoing operation. It provides callbacks that are called when the operation completes, as well as a reference to the operation's result. A DOM method that initiates an ongoing operation may return a DOMRequest object that you can use to monitor the progress of that operation.
interface DOMRequest<T> extends EventTarget {
readonly error?: Error;
readonly result: T;
onsuccess: (e: Event & { target: DOMRequest<T> }) => void;
onerror: (e: Event & { target: DOMRequest<T> }) => void;
readonly then: Promise<T>["then"];
readonly readyState: "done" | "pending";
}
DOMRequest.readyState
DOMRequest.result
DOMRequest.error
DOMRequest.onsuccess
success event; it is triggered when the operation represented by the DOMRequest is completed.DOMRequest.onerror
error event; it is triggered when an error occurs while processing the operation.DOMRequest.then()
Promise.then where the result/error is the argument to the callbacksAn example of using the onsuccess, onerror, result, and error properties of a DOMRequest object.
var pending = navigator.mozApps.install(manifestUrl);
pending.onsuccess = function () {
// Save the App object that is returned
var appRecord = this.result;
alert('Installation successful!');
};
pending.onerror = function () {
// Display the name of the error
alert('Install failed, error: ' + this.error.name);
};
An example using the Promise-based API.
const pending = navigator.mozApps.install(manifestUrl);
pending.then((result) => {
// Save the App object that is returned
const appRecord = result;
alert('Installation successful!');
}, (error) => {
// Display the name of the error
alert('Install failed, error: ' + error.name);
})