Onclick event throwing “unpromised error rejection” Works in preview but no published site. Here is my code. Any thoughts?
export function text1_click_1 ( event ) {
$w ( ‘#audioPlayer2’ ). togglePlay ();
}
Onclick event throwing “unpromised error rejection” Works in preview but no published site. Here is my code. Any thoughts?
export function text1_click_1 ( event ) {
$w ( ‘#audioPlayer2’ ). togglePlay ();
}
When do you get the error? Is it every time that you click? What else are you doing in the code?
Not sure if this makes any difference, but togglePlay() returns a Promise which isn’t being handled. In your case, not sure that it matters.
Thanks for your reply @yisrael-wix . After further testing I discovered that this only happens in iOS (in all browsers) and in Safari on desktop (when published). On Android and all PC browsers works just fine.
I get the error every time I click. Nothing else is going on in the code. No looping of audio etc. Here is link (its currently being built). Just logo and two single audio clips: https://kmellen.wixsite.com/sheri-reda
Thanks again @yisrael-wix for pinpointing the issue and trying to solve. Next time I will sit the full error.
This appears to be an issue regarding browser security settings. I tried this on Safari on my Mac and now I see the full error message:
Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
Please note that you need to provide all of the relevant information when asking for assistance.
The problem is a browser security issue. For some reason, Safari requires some sort of interaction with the Player before allowing programmatic play. So, if you first click on the Players’s play button, it will then work when subsequently calling play() or togglePlay() in code. I played with this for a while and so far I can’t find a workaround in code.