Skip to content
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

Cannot play video with XCDYouTubeVideoErrorDomain Code: -2 #557

Open
cou929 opened this issue Jun 2, 2022 · 0 comments
Open

Cannot play video with XCDYouTubeVideoErrorDomain Code: -2 #557

cou929 opened this issue Jun 2, 2022 · 0 comments

Comments

@cou929
Copy link

cou929 commented Jun 2, 2022

I encountered a situation where the video cannot play with the following error.

Domain: XCDYouTubeVideoErrorDomain
Code:   -2
User Info: {
}

It seems that sometimes YouTube returns some pattern of HTML that makes the parser fails.

  • To parse videoInfo from YouTube's HTML, find a string that matches ytInitialPlayerResponse = {...} by using this regex and deserialize it to json
  • But sometimes YouTube returns HTML which contains }; inside JSON, which makes it fail to deserialize
    • I still don't know the exact condition for Youtube to return such HTML, but it's definitely happening once in a while
<script nonce="tZD2YtPt7fxsKqPJwe7GAw">var ytInitialPlayerResponse = {
...
// This "privateDoNotAccessOrElseSafeScriptWrappedValue" key contains the JavaScript source code which contains `};`
"privateDoNotAccessOrElseSafeScriptWrappedValue": "(function(){function u(x){return x}var X=this||self,C=function(x,O,W,R,J){if(R=(J=X.trustedTypes,W),!J||!J.createPolicy)return R;try{R=J.createPolicy(O,{createHTML:y,createScript:y,createScriptURL:y})}catch(z){if(X.console)X.console[x](z.message)}return R},y=function(x){return u.call(this,x)}; ...",
...
}}}};var meta = document.createElement('meta'); meta.name = 'referrer'; meta.content = 'origin-when-cross-origin'; document.getElementsByTagName('head')[0].appendChild(meta);</script>

Is there anybody who encountered the same issue? How do we fix this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant