You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you run a sequence of promises and you are relying on finished property it will fail in Safari.
After doing some research, I stumbled upon this polyfill that fixes the issue and am pasting it here in case it helps anyone else. Ideally this library should include this code as well.
// only polyfill .finished in browsers that already support animate()if(document.body.animate){// Chrome does not seem to expose the Animation constructor globallyif(typeofAnimation==="undefined"){window.Animation=document.body.animate({}).constructor;}if(!Animation.prototype.hasOwnProperty("finished")){Object.defineProperty(Animation.prototype,"finished",{get(){if(!this._finished){this._finished=this.playState==="finished" ?
Promise.resolve() :
newPromise((resolve,reject)=>{this.addEventListener("finish",resolve,{once: true});this.addEventListener("cancel",reject,{once: true});});}returnthis._finished;}});}}
The text was updated successfully, but these errors were encountered:
Not only Safari. Chrome does not support that too. Alternatively, you can leverage finish event to achieve the same result:
constdivEl=document.body.querySelector('.animatable');constfadeOutAnimation=newPromise(yay=>divEl.animate([{opacity: '1'},{opacity: '0'},]).onfinish=yay);fadeOutAnimation.then(()=>/** Do more stuff */);
If you run a sequence of promises and you are relying on
finished
property it will fail in Safari.After doing some research, I stumbled upon this polyfill that fixes the issue and am pasting it here in case it helps anyone else. Ideally this library should include this code as well.
The text was updated successfully, but these errors were encountered: