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 read properties of undefined (reading 'playlistData') #1720

Closed
raszpl opened this issue Jul 30, 2023 · 3 comments
Closed

Cannot read properties of undefined (reading 'playlistData') #1720

raszpl opened this issue Jul 30, 2023 · 3 comments
Labels
Bug Bug or required update after YouTube changes good first issue A GitHub standard for inviting (new) contributors *Congratulations in advance!* help wanted Just an old github standard we add automatically. (The team can remove it when working on it.) up-for-grabs (a github standard for inviting new contributors) - Welcome! ♥

Comments

@raszpl
Copy link
Contributor

raszpl commented Jul 30, 2023

Bug Report:

BUG:

extension crashes with "Cannot read properties of undefined (reading 'playlistData')"

HOW:

1 satus.storage.clear()
2 import settings attached below
3 go to a playlist, for example: https://www.youtube.com/playlist?list=PLqPaeYdiNYymLVvaUjj4AzIDJBGQ2kCOl
4 click on one of the videos, for example position 11 with this link url: https://www.youtube.com/watch?v=Y0fiNUqqRic&list=PLqPaeYdiNYymLVvaUjj4AzIDJBGQ2kCOl&index=11&pp=iAQB
5 we land on url: https://www.youtube.com/watch?v=zvBZ-Tm2fbU&list=PLqPaeYdiNYymLVvaUjj4AzIDJBGQ2kCOl&index=11
6 console gets this:

Uncaught TypeError: Cannot read properties of undefined (reading 'playlistData')
    at ImprovedTube.playlistUpNextAutoplay (playlist.js:12:27)
    at ImprovedTube.playerOnPause (functions.js:383:15)
ImprovedTube.playlistUpNextAutoplay @ playlist.js:12
ImprovedTube.playerOnPause @ functions.js:383

I tried narrowing it down by cutting settings in half, error doesnt show up if I try either upper or just lower half of attached settings :o Its a combination of playlist_up_next_autoplay = false to jump into

this.elements.ytd_watch.playlistData.currentIndex = this.elements.ytd_watch.playlistData.totalVideos

and one other settings somehow causing ytd_watch creation that is happening here
this.elements.ytd_watch = node;
to be delayed sufficiently to let this event fire first
ImprovedTube.playlistUpNextAutoplay(event);

Edit: it might not even be a specific setting delaying, I just noticed playlistUpNextAutoplay is triggered automagically by playerOnPause here https://github.com/code-charity/youtube/blob/3e1b34e35e73743161100f06ce6d6e2cdb466060/js%26css/web-accessible/functions.js#L305C35-L305C61 as soon as video starts playing and is auto paused. It might be as simple as number of settings to process is enough to delay? in any case this is a logical error (use before initialization).

Setup:

⚬ ImprovedTube Version: 4.20
⚬ Browser: Chrome/114.0.0.0
⚬ Settings:
{"player_hide_skip_overlay":false,"player_popup_button":false,"player_quality":"hd1080","player_remaining_duration":false,"player_rotate_button":false,"player_show_cards_on_mouse_hover":false,"player_size":"max_width","player_subtitles":false,"player_transparent_background":false,"playlist_autoplay":false,"playlist_up_next_autoplay":false}
⚬ OS: W10

@raszpl raszpl added Bug Bug or required update after YouTube changes help wanted Just an old github standard we add automatically. (The team can remove it when working on it.) good first issue A GitHub standard for inviting (new) contributors *Congratulations in advance!* up-for-grabs (a github standard for inviting new contributors) - Welcome! ♥ labels Jul 30, 2023
@ImprovedTube
Copy link
Member

adding if (this.elements.ytd_watch.playlistData)
(no fix, just avoiding crash)

ImprovedTube added a commit that referenced this issue Sep 9, 2023
ImprovedTube added a commit that referenced this issue Sep 9, 2023
ImprovedTube added a commit that referenced this issue Jan 12, 2024
@raszpl
Copy link
Contributor Author

raszpl commented Jun 16, 2024

yay my old bug, lets revisit

ImprovedTube.playlistUpNextAutoplay = function (event) {
if (
ImprovedTube.getParam(location.href, 'list') &&
ImprovedTube.storage.playlist_up_next_autoplay === false
) {
try { if (this.elements.ytd_watch.playlistData)
{this.elements.ytd_watch.playlistData.currentIndex = this.elements.ytd_watch.playlistData.totalVideos}
else {var tries = 0; var intervalMs = 300; var maxTries = 6;
var waitForPlaylist = setInterval(() => {
if (this.elements.ytd_watch.playlistData || (++tries >= maxTries) ) {
this.elements.ytd_watch.playlistData.currentIndex = this.elements.ytd_watch.playlistData.totalVideos; clearInterval(waitForPlaylist );}
intervalMs *= 1.4;}, intervalMs);
} } catch (error) { console.error("Waiting for playlist", error);}
}
};

Not this horrible code again ! :D reminds me of autoplayDisable :]. Similarly here it does nothing but crashes because this.elements.ytd_watch.playlistData doesnt exist inside setinterval. At least here its inside try{} and could actually work in theory with fixed scope, but it would be much better to fix it properly.

There is no need for trying to force run it, proper fix is testing for this.elements.ytd_watch?.playlistData. playlistUpNextAutoplay is being called on every pause/stop and will take effect at right moment at the end of video. Problem here was player_autoplay_disable || playlist_autoplay stopping video before this.elements.ytd_watch was available, but its guaranteed to be there at the end of video.

@ImprovedTube
Copy link
Member

old

almost young

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug or required update after YouTube changes good first issue A GitHub standard for inviting (new) contributors *Congratulations in advance!* help wanted Just an old github standard we add automatically. (The team can remove it when working on it.) up-for-grabs (a github standard for inviting new contributors) - Welcome! ♥
Projects
None yet
Development

No branches or pull requests

2 participants