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; }