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

bug(Angular Youtube player: Getting YT is undefined in Pause video function #29030

Closed
1 task
mattiLeBlanc opened this issue May 10, 2024 · 7 comments · Fixed by #29127
Closed
1 task

bug(Angular Youtube player: Getting YT is undefined in Pause video function #29030

mattiLeBlanc opened this issue May 10, 2024 · 7 comments · Fixed by #29127
Assignees
Labels
area: youtube-player P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@mattiLeBlanc
Copy link

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

For one of our clients we see a lot of errors like YT is not definedReferenceError: YT is not defined.
When I check the source of the error, it is happening in

   /** See https://developers.google.com/youtube/iframe_api_reference#pauseVideo */
    pauseVideo() {
        if (this._player) {
            this._player.pauseVideo();
        }
        else {
            this._getPendingState().playbackState = YT.PlayerState.PAUSED;
        }

YT is not available somehow.

I haven;t been able to reproduce this error so I don't know if it is a firewall related issue, that some youtube code gets flittered out?

Reproduction

I can't reproduce this issue in Stackblitz because it is an internal source code issue.
the Code I use for using the player is:

<youtube-player [height]="height" [width]="width"  (stateChange)="stateChange($event)" [playerVars]="playerVars" #youtubePlayer></youtube-player>

Expected Behavior

No error when pausing video

Actual Behavior

Throwing YT is undefined error

Environment

  • Angular: 17
  • CDK/Material: 17
  • Browser(s): 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36`
  • Operating System (e.g. Windows, macOS, Ubuntu): Android table
@mattiLeBlanc mattiLeBlanc added the needs triage This issue needs to be triaged by the team label May 10, 2024
@amysorto
Copy link
Contributor

It looks like that error is surfaced directly from the YouTube API. It's certainly odd that is cannot be reproduced either on your end. Its interesting you are only seeing an error like this on pause and not on initialization or play, so I doubt things are getting filtered out otherwise it would have failed before.

Is this happening consistently for users who are seeing it?

@amysorto amysorto added needs: clarification The issue does not contain enough information for the team to determine if it is a real bug area: youtube-player and removed needs triage This issue needs to be triaged by the team labels May 10, 2024
@mattiLeBlanc
Copy link
Author

@amysorto Hi Amy,
I have to reach out to our customer using our product that triggers the error. When I go to the same video, it is working fine.
I hope they can tell me what they do or if there are any things filtered by their corporate wifi.

I have checked our logs and it happens mostly for 2 users, but one of the users triggers 90% of this error over the last 3 months, like every week.
Device is always 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36.
I will investigate further.

@crisbeto
Copy link
Member

Random thought: could it be something like an ad blocker that is blocking the Youtube script?

@mattiLeBlanc
Copy link
Author

@crisbeto yes, that could very well be the case. I just want to make sure I look at all angles.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs: clarification The issue does not contain enough information for the team to determine if it is a real bug labels May 28, 2024
@crisbeto crisbeto self-assigned this May 28, 2024
crisbeto added a commit to crisbeto/material2 that referenced this issue May 28, 2024
…e API has been loaded

Fixes a couple of issues:
1. We were using the `PlayerState` enum before the API has been loaded which will cause a runtime error because the enum is usually read off the `window`.
2. Fixes that calling the `playVideo` method wasn't load the YouTube API.

Fixes angular#29030.
crisbeto added a commit that referenced this issue May 28, 2024
…e API has been loaded (#29127)

Fixes a couple of issues:
1. We were using the `PlayerState` enum before the API has been loaded which will cause a runtime error because the enum is usually read off the `window`.
2. Fixes that calling the `playVideo` method wasn't load the YouTube API.

Fixes #29030.
crisbeto added a commit that referenced this issue May 28, 2024
…e API has been loaded (#29127)

Fixes a couple of issues:
1. We were using the `PlayerState` enum before the API has been loaded which will cause a runtime error because the enum is usually read off the `window`.
2. Fixes that calling the `playVideo` method wasn't load the YouTube API.

Fixes #29030.

(cherry picked from commit 883466e)
@mattiLeBlanc
Copy link
Author

@crisbeto Does this mean using the latest version of this component or is the fix happening in youtube source code?

@mattiLeBlanc
Copy link
Author

And thank you for picking this up

@crisbeto
Copy link
Member

It should be fixed when you update @angular/youtube-player.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: youtube-player P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
3 participants