WebKit2.WebView (and Gnome Browser) doesn't play YouTube videos

Inside a Python GTK+ 3 application I have a simple WebKit2.WebView (no customization) to display a set html string (no live browsing). The html contains a javascript lightbox with some youtube videos. When I open them, the youtube video box shows up but the content doesn’t play and I get a black screen saying (“An error occurred. Please try again later. (Playback ID: …”).
Similar image found on the web: https://i.redd.it/gwqswatndiy11.png

I then tried browsing the YouTube website with the Gnome Web browser (v 3.18.11 on Linux Mint 18.3) [based on WebKit] and the same problem occured with every video.
Of course everything works with other browsers (Chromium and Firefox).
Moreover, everything works if I use WebKit1 instead of WebKit2 in my PyGtk+ 3 app.
So I think the problem lies in the Webkit2 options configuration.

Does anyone know how to solve this problem?

Here is an extract of my code. As you can see, I have already tried to set some options but nothing worked.
[Side note: browser_settings.set_enable_media(True) gives me the error AttributeError: 'Settings' object has no attribute 'set_enable_media'; I don’t understand why since in the documentation the method exists]

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, GtkSource, GLib, WebKit2

self.webview = WebKit2.WebView.new()
browser_settings = self.webview.get_settings()
browser_settings.set_property('javascript-can-access-clipboard', bool(True))

# browser_context = self.webview.get_context()
# cookie_manager = browser_context.get_cookie_manager()
# cookie_manager.set_accept_policy(WebKit2.CookieAcceptPolicy.ALWAYS)
# browser_settings.set_enable_xss_auditor(False)
# browser_settings.set_allow_universal_access_from_file_urls(True)
# browser_settings.set_allow_file_access_from_file_urls(True)
# browser_settings.set_enable_media(True)
# browser_settings.set_enable_media_capabilities(True)
# browser_settings.set_enable_media_stream(True)
# browser_settings.set_enable_mediasource(True)
# browser_settings.set_media_playback_allows_inline(True)

self.webview.set_settings(browser_settings)

I just tested on Fedora 33 with Epiphany (GNOME Web) 3.38.2, and Youtube videos played OK. (Seemed to take a huge amount of CPU, but I guess that’s a separate issue).

You mentioned v3.18.11, this is a very old version and may not have some thing that’s needed to work with current Youtube.

If it’s impossible for you to use a recent version for some reason, I’d suggest opening the developer console in Web by pressing F12, and look in the console for any errors that might give a clue what’s wrong.

First of all, thank you very much for taking the time to assist other users like me. It’s much appreciated.

I run Linux Mint 18.3 (which is a LTS version with support until 2021) with everything updated, so apparently the only available package for Gnome Web browser is quite old. Can that happen in a LTS version?

That is reassuring. At least updating the package (by upgrading distro) is one solution.

In the console I get these two types of error:

I think it’s related to cross-origin requests, but I couldn’t find a solution… So frustrating…

I also think that more than Gnome Web browser / Epiphany versions, we should compare WebKit2 versions.
In the software manager I found that I have installed the following package:
gir1.2-webkit2-4.0, version 2.20.5

Which are you running?

I have version 2.30.4 of the webkit2gtk3 Fedora package.

I run Linux Mint 18.3 (which is a LTS version with support until 2021) with everything updated, so apparently the only available package for Gnome Web browser is quite old. Can that happen in a LTS version?

Very much so. LTS distributions deliberately avoid updating to newer versions of components, which is a tradeoff that sometimes pays off and sometimes doesn’t.

Have you looked at Flatpak? This provides a nice way to use up-to-date apps and libraries on older distros, by running the app in a special container. You can try GNOME Web from Flatpak and see if it works any better.

That makes sense. I just saw that the “current” WebKit2 version in Mint 18.3 was actually released in August 13th, 2018.

Since Mint 18.3 is coming to end-of-life I’ll just install Mint 20 (or Fedora) on another ssd disk and check if this issue is solved (I’ll need to upgrade the system anyway in a few months, so no harm starting now).

Thank you very much. I will mark the topic as closed as soon as I verify everyting on the new system (at most in a few days).

FYI, Linux Mint 20.1 should be released anytime soon, so you should get the latest packages there.

Thank you for the reminder

1 Like

Confirmed that the probelm is no longer present in Linux Mint 20, with newer package versions of WebKit2. Thank you very much!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.