My app started failing recently. I have not been able to get it to work again using the solutions found in the comments on this post. My app has been running without problem for over five years.
Adding these to the YTPlayer vars solved the Error 153
origin: 'https://www.youtube.com',
widget_referrer: 'https://www.youtube.com'
But, the video does not play. The message An error occurred. Please try again later. (Playback ID: l3D74od3j9GXjKY-) is displayed. I right-clicked on the WebView2 display and then clicked debug info. The JSON below was displayed.
"api.invalidparam" and "invalidVideodata.1;a6s.1" indicate a problem but I don't have any idea what else to change.
{ "vct": "0.000", "vd": "NaN", "vpl": "", "vbu": "", "vbs": "", "vpa": "1", "vsk": "0", "ven": "0", "vpr": "1", "vrs": "0", "vns": "0", "vec": "null", "vemsg": "", "vvol": "1", "vdom": "1", "vsrc": "0", "vw": "0", "vh": "0", "dvf": 0, "tvf": 0, "state": "80", "debug_error": "{\"errorCode\":\"api.invalidparam\",\"errorMessage\":\"An error occurred. Please try again later.\",\"gN\":\"GENERIC_WITHOUT_LINK\",\"UY\":\"\",\"hf\":\"invalidVideodata.1;a6s.1\",\"QM\":2,\"cpn\":\"Mk4qbbDE9eZ6_uIk\"}", "relative_loudness": "NaN", "user_qual": 0, "release_version": "youtube.player.web_20251029_15_RC00", "0sz": "true", "op": "", "yof": "true", "dis": "", "gpu": "ANGLE_(Intel,_Intel(R)_UHD_Graphics_(0x00009A60)_Direct3D11_vs_5_0_ps_5_0,_D3D11)", "js": "/s/player/e237d4c5/player_ias.vflset/en_US/base.js", "debug_playbackQuality": "unknown", "debug_date": "Mon Nov 03 2025 13:12:54 GMT-0500 (Eastern Standard Time)", "origin": "https://www.youtube.com", "timestamp": 1762193574713 }
It is a Windows app that uses (.NET and WebView2). The app passes the HTML via string containing the YTPlayer JavaScript to the WebView2 API using WebView.NavigateToString(HTMLText);
Sample contents of the HTMLText string passed to WebView2:
Added to original HTMLText as a result of comments in this post:
<meta name='referrer' content='strict-origin-when-cross-origin'>
origin: 'https://www.youtube.com',
widget_referrer: 'https://www.youtube.com
<!doctype html>
<html lang='en'>
<head>
<title>YouTube Player</title>
<meta charset='UTF-8'>
<meta name='robots' content='none,noarchive,noindex,nofollow,nosnippet,noimageindex,unavailable_after: 01 Jan 2010 01:00:00 PST'>
<meta name='googlebot' content='noarchive,noindex,nofollow,nosnippet,noimageindex,unavailable_after: 01 Jan 2010 01:00:00 PST'>
<meta name='referrer' content='strict-origin-when-cross-origin'>
<style>
.video-container {position:relative;padding-bottom:56.25%;padding-top:0px;height:0;overflow:hidden;}
.video-container iframe, .video-container object, .video-container embed {position:absolute;top:0;left:0;width:100%;height:100%;}
</style>
</head>
<body>
<div class='video-container'><div id='ytplayer'></div></div>
<script>
var TheVID = ' The YouTube Video ID Godes Here';
var player;
var videoCount = 0;
var lastState = -1;
function SendMsg(msg) {
window.chrome.webview.postMessage(msg); // Send Message to program
}
function handlePaused() {
// If still paused after 10 seconds, send error and exit
if (lastState == YT.PlayerState.PAUSED) {
// Send error message to program
// Force a Navigation event
SendMsg('ERROR: YouTube ID=' + TheVID + ' paused unexpectedly. Exiting play.');
setTimeout(function(){window.location='about:blank';}, 5000); // Wait 5 seconds then exit
}
}
function onPlayerReady(event) {
if (TheVID.indexOf(',') > -1) {
var VIDList = TheVID.split(',');
videoCount = VIDList.length;
player.loadPlaylist(VIDList);
} else {
videoCount = 1;
player.loadVideoById(TheVID);
}
// Wait a bit. Supposed to AutoPlay but just in case it doesn't...tell it to play
setTimeout(function(){player.playVideo();}, 500);
}
window.onYouTubeIframeAPIReady = function() {
var vars = {enablejsapi: 1,
rel: 0, playsinline: 0, loop: 0, fs: 0, controls: 0,
autoplay: 1,
origin: 'https://www.youtube.com',
widget_referrer: 'https://www.youtube.com'
};
window.scrollbars.visible=false;
player = new YT.Player('ytplayer', {
playerVars: vars,
events: {
'onReady': onPlayerReady,
'onStateChange': function (event) {
if (event.data == YT.PlayerState.ENDED) {
videoCount = videoCount - 1;
if (videoCount == 0) {
// Force a Navigation event
window.location='about:blank';
}
}
if (event.data == YT.PlayerState.PAUSED) {
lastState = event.data;
SendMsg('WARNING: YouTube ID=' + TheVID + ' paused unexpectedly. Trying to resume playing.');
player.playVideo(); // Attempt to make it play again
setTimeout(handlePaused,10000); // Wait 10 seconds then check to see if play has resumed.
}
if (event.data == YT.PlayerState.PLAYING) {
lastState = event.data;
SendMsg('YouTube video is now playing.');
}
},
'onError': function (event) {
// Send error message to program
// Force a Navigation event to end the YouTube Player
var msg;
switch (event.data.toString()) {
case '2' :
msg=' The request contains an invalid parameter value (VideoID).';
break;
case '5' :
msg=' The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred.';
break;
case '100' :
msg=' The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private.';
break;
case '101' :
msg=' The owner of the requested video does not allow it to be played in embedded YouTube player';
break;
case '150' :
msg=' Allow Embedding not checked, Private checked or copyright claim prevents play in embedded YouTube player';
break;
default :
msg=' Error #' + event.data.toString();
break;
}
SendMsg('ERROR: YouTube ID=' + TheVID + ' ' + event.data.toString() + msg);
setTimeout(function(){window.location='about:blank';}, 5000); // Wait 5 seconds then exit
}
}
});
};
// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
//
// Replaces the 'ytplayer' element with an <iframe> and
// YouTube player after the API code downloads.
</script>
</body>
</html>