From 4772efb483473f2a1f0f4268589bfe9a6002838d Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sat, 26 Oct 2024 07:20:39 +0200 Subject: [PATCH] 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 --- src/plugins/GreaseMonkey/gm_downloader.cpp | 7 +++++++ src/plugins/GreaseMonkey/gm_plugin.cpp | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/GreaseMonkey/gm_downloader.cpp b/src/plugins/GreaseMonkey/gm_downloader.cpp index cd2d0eb21..dd84cb526 100644 --- a/src/plugins/GreaseMonkey/gm_downloader.cpp +++ b/src/plugins/GreaseMonkey/gm_downloader.cpp @@ -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=="))) { diff --git a/src/plugins/GreaseMonkey/gm_plugin.cpp b/src/plugins/GreaseMonkey/gm_plugin.cpp index 5700e844d..2d467edde 100644 --- a/src/plugins/GreaseMonkey/gm_plugin.cpp +++ b/src/plugins/GreaseMonkey/gm_plugin.cpp @@ -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; }