Bug 1178738 - Update narrator to use error events when narration is stopped. r?Gijs
MozReview-Commit-ID: L9Bd2WDdlMp
--- a/toolkit/components/narrate/Narrator.jsm
+++ b/toolkit/components/narrate/Narrator.jsm
@@ -172,39 +172,44 @@ Narrator.prototype = {
this._sendTestEvent("paragraphstart", {
voice: utterance.chosenVoiceURI,
rate: utterance.rate,
paragraph: paragraph.textContent
});
}
});
- utterance.addEventListener("end", () => {
+ let onDone = (e) => {
if (!this._win) {
// page got unloaded, don't do anything.
return;
}
+ if (e.type == "error" &&
+ !(['interrupted', 'canceled'].includes(e.error))) {
+ reject("speech synthesis failed");
+ return;
+ }
+
paragraph.classList.remove("narrating");
this._startTime = 0;
if (this._inTest) {
this._sendTestEvent("paragraphend", {});
}
if (this._stopped) {
// User pressed stopped.
resolve();
} else {
this._speakInner().then(resolve, reject);
}
- });
+ };
- utterance.addEventListener("error", () => {
- reject("speech synthesis failed");
- });
+ utterance.addEventListener("end", onDone);
+ utterance.addEventListener("error", onDone);
this._win.speechSynthesis.speak(utterance);
});
},
start: function(speechOptions) {
this._speechOptions = {
rate: speechOptions.rate,