1

I'm having a WebBrowser application that uses the QWebEngineView (Qt 5.9). I want to load a page, where a Youtube video is embedded. The page loads perfectly but the video is not working. The message I get when it tries to start is:
Requests to the server have been blocked by an extension.

I tried to activate plugins and set the feature permission but none of it makes any difference.

m_webView->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);

m_webView->page()->setFeaturePermission(QUrl("https://www.youtube.com/watch?v=rNSnfXl1ZjU"),
                                    QWebEnginePage::MediaAudioVideoCapture,
                                    QWebEnginePage::PermissionGrantedByUser);

I'm kind of new to Qt. Do I need to enable video codecs? Thank you very much in advance, I hope you can help me.

Rex5
  • 771
  • 9
  • 23
Vanessa
  • 49
  • 8

1 Answers1

0

The following small App, works as desired. In case that I uncomment the settings section in my small App, it locks the playing of the YouTube video.

I suggest that you manually activate all settings one by one to figure out what prevents the video from running in your environment.

The console output might be also very helpful to find the cause for your problem.

#include <QWebEngineView>
#include <QWebEngineSettings>
#include <QApplication>

int main(int argc, char **args)
{
    QApplication app(argc, args);
    auto view = new QWebEngineView; 
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::AllowGeolocationOnInsecureOrigins, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::Accelerated2dCanvasEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::AllowRunningInsecureContent, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::AllowWindowActivationFromJavaScript, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::JavascriptCanAccessClipboard, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::FullScreenSupportEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::JavascriptCanOpenWindows, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::JavascriptEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::ScreenCaptureEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::PluginsEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::LocalStorageEnabled, false);

    view->setUrl(QUrl("https://www.youtube.com/watch?v=rNSnfXl1ZjU"));
    view->show();
    app.exec();
}

With all settings deactivated I'm left with the following console output:

js: Refused to display 'https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252Fsignin_passive%26hl%3Dde%26feature%3Dpassive%26app%3Ddesktop%26action_handle_signin%3Dtrue&hl=de&passive=true&service=youtube&uilel=3' in a frame because it set 'X-Frame-Options' to 'deny'.
Aleph0
  • 5,816
  • 4
  • 29
  • 80
  • 1
    First of all: Thank you very much for answering me! I tried this small example and it works for me too. But in my big project it still doesn't work. I'm not really sure if some other stuff is blocking this then... maybe the QWebEngineUrlRequestInterceptor could cause some trouble? But I think I need to figure this out somehow on my own, because that is way to much code to post here. Thank you again! – Vanessa Jun 26 '19 at 07:10
  • @Vanessa: If I have some defect, I'll try to build a small side project or even better a test, that will just reproduce this defect. Then you will have a minimal-reproducible-example (Which can of course be posted here, but also would help you much.) – Aleph0 Jun 26 '19 at 08:31
  • Thank you very much, I take everything that can help! :) – Vanessa Jun 26 '19 at 08:49
  • 1
    I found the problem. It is the QWebEngineUrlRequestInterceptor. We have a whitelistening, but the problem is that I allow "www.youtube.com" for example, but the video comes from a CDN which we don't know... – Vanessa Jun 26 '19 at 10:55