I'm pretty sure YouTube Iframe API "onError" event will fire in the past since I run a project based on this API. But recently "onError" event will not fire, even the simplest error.
This is a simple sample code based on official page( https://developers.google.com/youtube/iframe_api_reference ) and is workable:
<iframe id="existing-iframe-example"
width="640" height="360"
src="https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1"
frameborder="0"
style="border: solid 4px #37474F"
></iframe>
<script type="text/javascript">
var tag = document.createElement('script');
tag.id = 'iframe-demo';
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('existing-iframe-example', {
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError': onError
}
});
}
function onError(event) {
console.log(event.data)
}
function onPlayerReady(event) {
}
function onPlayerStateChange(event) {
console.log(event.data);
}
</script>
Once change the video id string "M7lc1UVf-VE" as a wrong one, such as "M7lc1UVf", it should fire "onError" event, but doesn't now.
According to official page guide: https://developers.google.com/youtube/players/support → "Google engineers monitor and answer questions with the youtube-iframe-api tag", hope Google engineers can see this post and fix the "onError" problems.