Skip to content

Cannot play video with XCDYouTubeVideoErrorDomain Code: -2 #557

@cou929

Description

@cou929

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions