-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
catch unhandled Promise in decodeAudioData #2079
Conversation
headless is broken since Chrome 83 for some reason.
Interesting to see these errors on firefox: https://travis-ci.org/github/katspaugh/wavesurfer.js/builds/731591098#L1254
Where is this promise rejected.. |
When I replace the existing diff --git a/src/webaudio.js b/src/webaudio.js
index 65a41b2..cb4e716 100755
--- a/src/webaudio.js
+++ b/src/webaudio.js
@@ -348,11 +348,18 @@ export default class WebAudio extends util.Observer {
this.ac && this.ac.sampleRate ? this.ac.sampleRate : 44100
);
}
+ this.offlineAc.decodeAudioData(arraybuffer).then(
+ (data) => callback(data)
+ ).catch(
+ (err) => errback(err)
+ );
+ /*
this.offlineAc.decodeAudioData(
arraybuffer,
data => callback(data),
errback
);
+ */
}
/** I don't see these errors anymore. According to https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/decodeAudioData the Promise based syntax of |
I've seen this error in a production app too, but they don't seem to break anything... Happens during load/unload I think. The tests seem to fail in places where wavesurfer calls methods like play() or pause() which should be promises, but the wavesurfer functions are synchronous. |
That Promise exception needs to be handled though. |
How would I properly check if Promise syntax is supported (without checking for Safari user-agent)? |
What is it though? Decoding interrupted because destroy() is called? |
Good question.. Something like that.. |
Use callbacks like this (first answer). you can create your own promise and resolve/reject in the callback. |
But I want to use Promise everywhere and your workaround on unsupported browsers only. How to check if a browser, e.g. Safari for example, supports it? |
Callbacks version is supported everywhere so we make our own promise version: async function decodeAudioDataAsync(ac, arrayBuffer) {
return new Promise((resolve, reject) => {
ac.decodeAudioData(arrayBuffer, resolve, reject);
});
} Usage: try {
const buffer = await decodeAudioDataAsync(audioContext, arrayBuffer);
// successfully decoded
} catch (err) {
console.error(err);
} Change as you see fit |
The thing is, this Promise unhandled rejection is only caught when using the Promise based syntax. When using the old syntax the Promise is not caught and that's the whole point of this fix: catch that Promise. |
I see. Check the return type of decodeAudioData? I guess it will return nothing on browsers that dont support promise syntax? |
|
Fortunately(?), Safari still uses |
It's |
Yea because I don't want to make a useless, extra call just to add a workaround for Safari. |
* ci: disable Chrome for now headless is broken since Chrome 83 for some reason. * use Chrome_dev locally * test: fix precision varying on different platforms * use promise-based syntax for decodeAudioData and make exception for Safari
* ci: disable Chrome for now headless is broken since Chrome 83 for some reason. * use Chrome_dev locally * test: fix precision varying on different platforms * use promise-based syntax for decodeAudioData and make exception for Safari
use promise-based syntax for decodeAudioData where possible.