I have an Angular 6 app that allows the user to record audio from within their browser and upload it to a server. For recording it uses the WebAudioTrack.js library, which is included via a <script>
tag because I couldn't find any way to compile it into the Angular app.
About half of the time the recording works fine. The rest of the time it works fine (with VU meter and everything) up until the point when the user clicks the stop button. When that happens, the Chrome console reports the error as:
Uncaught (in promise) DOMException
When I'm running Angular in development mode, the Chrome error messages usually include a link to the line of code that caused the error. In this case, though, the link just points to line 1 of the HTML page, i.e. the DOCTYPE line.
By inserting a lot of console.log
statements I was able to follow the program execution, and I believe I have partly narrowed down the source of the problem. It appears to be happening in the chunk of code below, at the line which calls this.audioTrack.stopRecording((e)
.
// "Stop" button was clicked
recordStop() {
/* Browser shows error when following line is called */
this.audioTrack.stopRecording((e) => {
/* When browser errs, this code is never reached */
this.blobWav = this.audioTrack.blob;
this.audioURL = this.audioTrack.getBlobSrc();
this.tearDownMediaStream();
this.recordState = 'playbackready';
window.clearInterval(this.timer);
});
}
Note that this does not appear to be related to the new Chrome autoplay policy which requires user interaction with a page before using an AudioContext to play audio, and throws similar error messages when a paused AudioContext is used. I have already taken that into account, and the state of the AudioContext is reported as "running". Also, this is recording, not playback.
I've tried checking the return value of this.audioTrack.stopRecording((e)
and outputting that to the console. Code:
recordStop() {
var retval = this.audioTrack.stopRecording((e) => {
// ...
});
console.log(retval);
}
Output:
WebAudioTrack {context: AudioContext, sampleRate: 48000, bufferSize: 4096, numberOfAudioChannels: 1, volume: 1, …}
So, I guess that's not a return value but a copy of the object.
I also tried adding a .catch to it, but it doesn't support that method.
I am stuck on what to do next to continue narrowing down the source of this intermittent error. I also am a bit overwhelmed by the syntax for promises, especially in Angular. I can barely manage to write them, so I'm not yet at the point where I am comfortable debugging them.
What can I do to get the browser to give me more detail on this error message? Or is there some way I can catch the DOMException, handle it, and output more detail?