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

Youtube do not autoplay anymore on Google Chrome #149

Closed
adrienjoly opened this issue Jun 30, 2018 · 13 comments
Closed

Youtube do not autoplay anymore on Google Chrome #149

adrienjoly opened this issue Jun 30, 2018 · 13 comments
Assignees

Comments

@adrienjoly
Copy link
Member

adrienjoly commented Jun 30, 2018

Situation, when clicking on a Youtube track, on Google Chrome:

screen shot 2018-06-30 at 12 24 07

=> The Youtube wrapper of Playemjs (the track player used by Openwhyd) may need a quick fix, e.g. by calling the playVideo() function instead of relying on the embed's autoplay setting.

Read more on how to do that: https://github.com/openwhyd/openwhyd/blob/96370c5c0dcfd198cc84909032ac0f13fd8ff3ed/docs/playemjs-fix-procedure.md

@adrienjoly
Copy link
Member Author

Just checked if the error was coming from Playemjs' Youtube player (adrienjoly/playemjs#18): it's not. => The problem must be coming from Openwhyd's patched version of the Youtube player (whydJS/public/js/playem-youtube-iframe.js).

=> Running Openwhyd's automated tests to see if they pass.

@adrienjoly
Copy link
Member Author

All automated tests pass.

My hypothesis is that Webdriver is using an old version of Google Chrome on which the bug was not happening.

=> Next check: manually test playback of youtube tracks from my local openwhyd instance, on the latest version of Chrome.

@adrienjoly
Copy link
Member Author

Youtube playback is also working from Openwhyd on localhost:

screen shot 2018-08-15 at 11 08 27

Hypothesis: while running locally, Openwhyd uses Playemjs' native Youtube player instead of whydJS/public/js/playem-youtube-iframe.js => let's find a way to play through this patched player instead, even from localhost.

@adrienjoly
Copy link
Member Author

Actually, it seems that whydJS/public/js/playem-youtube-iframe.js is not loaded by any page or module anymore, except an old test for Deezer.

image

=> added a comment, and going to check whydJS/public/js/playem-youtube-iframe-patch.js instead.

@adrienjoly
Copy link
Member Author

whydJS/public/js/playem-youtube-iframe-patch.js loads /html/YoutubePlayerIframeLocal.html or /html/YoutubePlayerIframe.html, depending on where Openwhyd is running (i.e. from localhost or openwhyd.org, respectively)

/html/YoutubePlayerIframeLocal.html or /html/YoutubePlayerIframe.html are basically the same file, except the latter explicitly loads playem-all.js and whydRemotePlayer.js from the openwhyd.org domain instead of using a relative path.

=> Let's investigate what whydRemotePlayer.js does.

@adrienjoly
Copy link
Member Author

adrienjoly commented Aug 15, 2018

Playback also works from localhost, when forcing IFRAME_PATH to/html/YoutubePlayerIframe.html instead of /html/YoutubePlayerIframeLocal.html.

=> let's now pretend that we're running from production => have IFRAME_HOST use the CDN.

EDIT: dumb idea, because doing that uses the CDN-cached version of YoutubePlayerIframe.html, which expects an ORIGIN of openwhyd.org for incoming messages, whereas the local instance sends from localhost => it cannot work => let's have a look of what's happening exactly when trying to play a youtube track from openwhyd.org, to see if we see an error message

@adrienjoly
Copy link
Member Author

Found in javascript logs when trying to play the youtube track from https://openwhyd.org/yt/aZT8VlTV1YY:

populating track list...

playem-youtube-iframe-patch.js?1.1.1:56 YT-iframe not ready => ignoring call to stop
Player.safeCall @ playem-youtube-iframe-patch.js?1.1.1:56

playem-youtube-iframe-patch.js?1.1.1:127 youtube iframe stop:

playem-min.js?1.1.1:2 DEEZER STOP

whydPlayer.js?1.1.1:555 evt: onTrackChange (Youtube)

playem-youtube-iframe-patch.js?1.1.1:56 YT-iframe not ready => ignoring call to setVolume

window.playTrack @ whydPlayer.js?1.1.1:771

whydPlayer.js?1.1.1:555 evt: loadMore

whydRemotePlayer.js:15 ORIGIN https://openwhyd.org

whydRemotePlayer.js:57 PLAYER YoutubePlayer {eventHandlers: {…}, embedVars: {…}, label: "Youtube", isReady: false, trackInfo: {…}, …}

VM591:1 Uncaught SyntaxError: Unexpected token ! in JSON at position 0
    at JSON.parse (<anonymous>)
    at playem-youtube-iframe-patch.js?1.1.1:35
(anonymous) @ playem-youtube-iframe-patch.js?1.1.1:35

base.js:6069 [Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952

@adrienjoly
Copy link
Member Author

While debugging the JSON parse error from playem-youtube-iframe-patch.js, I found that e.data has a the following value: !_{"h":""}. 🤔

I also found that this parse error and the "violation" warning are happening on the local instance as well, and does not prevent the video from starting.

@adrienjoly
Copy link
Member Author

adrienjoly commented Aug 15, 2018

Hypothesis: the bug happens only thru HTTPS (SSL).

Test: Try to play the youtube track from http://openwhyd.org/yt/aZT8VlTV1YY a new chrome incognito window, after disabling the "Protect you and your device from dangerous sites" setting. (to prevent the automatic HTTP-->HTTPS redirection)

Result: the track also does not play when using HTTP.

@adrienjoly
Copy link
Member Author

Hypothesis:

  • I need to use the CDN-bridged player patch in order to reproduce the bug
  • In order to do that, I need to setup a virtual host + port forwarding on my Mac, so that localhost:8080 is reachable thru openwhyd.org:80

1. attach openwhyd.org to localhost

cf https://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want

$ sudo code /etc/hosts
# add a line:`127.0.0.1	openwhyd.org` (separated by a tab) in that file
$ sudo killall -HUP mDNSResponder
# to refresh the local DNS cache

... and then open a new incognito chrome window => openwhyd.org:8080 works.

2. port forwarding 8080->80

cf https://serverfault.com/a/787565/284330
cf https://salferrarello.com/mac-pfctl-port-forwarding/

2.1. check current rules

$ sudo pfctl -s nat

No ALTQ support in kernel
ALTQ related functions disabled
nat-anchor "com.apple/*" all
rdr-anchor "com.apple/*" all

2.2. try the restore command

$ sudo pfctl -F all -f /etc/pf.conf

2.3. add the port forwarding

$ echo "
rdr pass inet proto tcp from any to openwhyd.org port 80 -> 127.0.0.1 port 8080
" | sudo pfctl -ef -

2.4. check current rules again

$ sudo pfctl -s nat
No ALTQ support in kernel
ALTQ related functions disabled
rdr pass inet proto tcp from any to 127.0.0.1 port = 80 -> 127.0.0.1 port 8080

=> it's working: I can access my localhost:8080 server from openwhyd.org (port 80) 🎉

3. try playing the youtube track from the fake openwhyd.org

@adrienjoly
Copy link
Member Author

adrienjoly commented Aug 15, 2018

Now that I'm able to test the real youtube playback behavior from my local openwhyd instance, let's try to apply playemjs' PR: https://github.com/adrienjoly/playemjs/pull/16/files, to see if it fixes the issue.

=> Plan:

  • apply the PR changes to the playem-all.js of openwhyd (temporary)
  • $ docker-compose restart web
  • hard-refresh the page in the incognito window and try to play the track again

=> still does not play

@adrienjoly adrienjoly self-assigned this Aug 15, 2018
@adrienjoly
Copy link
Member Author

Found the fix (at least working when testing locally): https://stackoverflow.com/a/48747474/592254

Google Chrome now requires to use a allow="autoplay" attribute in the iframe that displays a youtube video.

Let's commit the fix and test it in production!

adrienjoly added a commit that referenced this issue Aug 15, 2018
@adrienjoly
Copy link
Member Author

Fixed! 🍾

=> release and deploy v1.1.4 (https://github.com/openwhyd/openwhyd/releases/tag/v1.1.4)

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

No branches or pull requests

1 participant