Skip to content

Commit 78135f6

Browse files
committed
fix youtube embedding not working
1 parent be2d13d commit 78135f6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

QtLxBTSC.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TEMPLATE = lib
66
TARGET = QtLxBTSC
77
INCLUDEPATH += . QtLxBTSC ts_plugin/include
88
CONFIG += release qt c++11 plugin
9-
QT += network webchannel webenginewidgets widgets
9+
QT += core network gui widgets webchannel webenginewidgets
1010
DESTDIR = build
1111
OBJECTS_DIR = obj
1212
MOC_DIR = moc

QtLxBTSC/ChatWidget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <QWebEngineSettings>
1414
#include <QWebEngineProfile>
1515
#include <QTimer>
16+
#include <QWebEngineCookieStore>
1617

1718
ChatWidget::ChatWidget(const QString& path, TsWebObject* webObject, QWidget *parent)
1819
: QFrame(parent)
@@ -67,6 +68,7 @@ ChatWidget::ChatWidget(const QString& path, TsWebObject* webObject, QWidget *par
6768

6869
ChatWidget::~ChatWidget()
6970
{
71+
page->profile()->cookieStore()->setCookieFilter(nullptr);
7072
}
7173

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

99112
connect(page, &TsWebEnginePage::fullScreenRequested, this, &ChatWidget::onFullScreenRequested);
100113
connect(page, &TsWebEnginePage::linkHovered, this, &ChatWidget::onLinkHovered);

0 commit comments

Comments
 (0)