Skip to content

Commit

Permalink
fix youtube embedding not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Luch00 committed Apr 11, 2021
1 parent be2d13d commit 78135f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion QtLxBTSC.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TEMPLATE = lib
TARGET = QtLxBTSC
INCLUDEPATH += . QtLxBTSC ts_plugin/include
CONFIG += release qt c++11 plugin
QT += network webchannel webenginewidgets widgets
QT += core network gui widgets webchannel webenginewidgets
DESTDIR = build
OBJECTS_DIR = obj
MOC_DIR = moc
Expand Down
13 changes: 13 additions & 0 deletions QtLxBTSC/ChatWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QWebEngineSettings>
#include <QWebEngineProfile>
#include <QTimer>
#include <QWebEngineCookieStore>

ChatWidget::ChatWidget(const QString& path, TsWebObject* webObject, QWidget *parent)
: QFrame(parent)
Expand Down Expand Up @@ -67,6 +68,7 @@ ChatWidget::ChatWidget(const QString& path, TsWebObject* webObject, QWidget *par

ChatWidget::~ChatWidget()
{
page->profile()->cookieStore()->setCookieFilter(nullptr);
}

void ChatWidget::waitloop() const
Expand Down Expand Up @@ -95,6 +97,17 @@ void ChatWidget::setupPage() const
page->settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, true);
page->settings()->setUnknownUrlSchemePolicy(QWebEngineSettings::UnknownUrlSchemePolicy::AllowAllUnknownUrlSchemes);
page->profile()->setHttpUserAgent(QString("Twitterbot/1.0 %1").arg(QWebEngineProfile::defaultProfile()->httpUserAgent()));
page->profile()->cookieStore()->setCookieFilter(
[=](const QWebEngineCookieStore::FilterRequest &request) {
// block consent.youtube.com cookies
// fetch in embed.js gets redirected otherwise
// should probably modify how embedding is done instead
if (request.origin.host() == "consent.youtube.com") {
return false;
}
return true;
}
);

connect(page, &TsWebEnginePage::fullScreenRequested, this, &ChatWidget::onFullScreenRequested);
connect(page, &TsWebEnginePage::linkHovered, this, &ChatWidget::onLinkHovered);
Expand Down

0 comments on commit 78135f6

Please sign in to comment.