1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-19 18:26:34 +01:00

GreaseMonkey - Check content type of url *.user.js

- Do not stop loading the page with url matching user script
- Only match clicked links

BUG: 467459

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2024-10-26 07:20:39 +02:00
parent d3b1271e6d
commit 4772efb483
2 changed files with 9 additions and 3 deletions

View File

@ -58,6 +58,13 @@ void GM_Downloader::scriptDownloaded()
return;
}
QString contentType = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();
if (!(contentType.startsWith(QSL("text/plain")) || contentType.startsWith(QSL("text/javascript")))) {
qWarning() << "GreaseMonkey: Unsupported content type" << contentType;
Q_EMIT error();
return;
}
const QByteArray response = QString::fromUtf8(m_reply->readAll()).toUtf8();
if (!response.contains(QByteArray("// ==UserScript=="))) {

View File

@ -107,11 +107,10 @@ bool GM_Plugin::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEngi
Q_UNUSED(page)
Q_UNUSED(isMainFrame)
bool navigationType = type == QWebEnginePage::NavigationTypeLinkClicked || type == QWebEnginePage::NavigationTypeRedirect;
bool navigationType = type == QWebEnginePage::NavigationTypeLinkClicked;
if (navigationType && url.toString().endsWith(QLatin1String(".user.js"))) {
if (navigationType && url.fileName().endsWith(QLatin1String(".user.js"))) {
m_manager->downloadScript(url);
return false;
}
return true;
}