pseudosavant / player.html

One file drop-in media player web app for using video and audio files served using basic HTTP directory listing
MIT License
219 stars 40 forks source link

fix Firefox, Safari link click event #14

Closed noangel closed 2 years ago

noangel commented 2 years ago

Uncaught TypeError: e.path is undefined getTargetEl http://xxx/player.html:2603 clickLink http://xxx/player.html:2610

"The path property of Event objects is non-standard. The standard equivalent is composedPath, which is a method. But it's new. So you may want to try falling back to that" https://stackoverflow.com/questions/39245488/event-path-is-undefined-running-in-firefox

pseudosavant commented 2 years ago

Hey @noangel, thanks for the contribution! People rarely file bug reports with PRs. 😁

Looking up the info on composedPath(), it looks like it has been supported for a while by most browsers. I see e.composedPath in the StackOverflow answer, but it looks like it should only be the method.

With this having been supported for some time I was thinking the fix doesn't need to use e.path at all. It could be this:

const anchors = [...e.composedPath()].filter((el) => el.nodeName === 'A');

instead of

const anchors = [...e.path].filter((el) => el.nodeName === 'A');

What do you think?

noangel commented 2 years ago

@pseudosavant Yes, sure. I think it will be even better to use composedPath() only.

pseudosavant commented 2 years ago

I made the composedPath() changes on master.