diff --git a/webenginepart/src/webengineparthtmlembedder.h b/webenginepart/src/webengineparthtmlembedder.h
--- a/webenginepart/src/webengineparthtmlembedder.h
+++ b/webenginepart/src/webengineparthtmlembedder.h
@@ -51,6 +51,12 @@
*
* `QWebEnginePage::setHtml` -> `QWebEnginePage::loadFinished` -> startExtractingUrls() -> urlsExtracted() ->
* startReplacingUrls() -> urlsReplaced() -> startRetrievingHtml() -> htmlRetrieved() -> sendReply()
+ *
+ * A problem can arise if the (X)HTML code contains a `` element with attribute `http-equiv="refresh"`.
+ * Since QWebEnginePage is not just a parser, it honours this refresh request and, after emitting the `loadFinished`
+ * signal, it refreshes the page, which means that `loadFinished` is emitted again and again. To avoid
+ * doing the embeddding every time, the `loadFinished` signal is disconnected after the first time it's
+ * emitted and the connection is remade the next time startEmbedding() is called.
*
* @note This class uses and internal `QWebEnginePage` and an associated, off the record, `QWebEngineProfile`
* so as not interfere with the rest of the part
diff --git a/webenginepart/src/webengineparthtmlembedder.cpp b/webenginepart/src/webengineparthtmlembedder.cpp
--- a/webenginepart/src/webengineparthtmlembedder.cpp
+++ b/webenginepart/src/webengineparthtmlembedder.cpp
@@ -64,18 +64,21 @@
m_profile(new QWebEngineProfile(this)),
m_page(new QWebEnginePage(m_profile, this))
{
- connect(m_page, &QWebEnginePage::loadFinished, this, &WebEnginePartHtmlEmbedder::startExtractingUrls);
connect(this, &WebEnginePartHtmlEmbedder::urlsExtracted, this, &WebEnginePartHtmlEmbedder::startReplacingUrls);
connect(this, &WebEnginePartHtmlEmbedder::urlsReplaced, this, &WebEnginePartHtmlEmbedder::startRetrievingHtml);
}
void WebEnginePartHtmlEmbedder::startEmbedding(const QByteArray& html, const QString& mimeType)
{
+ //Try avoiding problems with redirection (see documentation for this class)
+ connect(m_page, &QWebEnginePage::loadFinished, this, &WebEnginePartHtmlEmbedder::startExtractingUrls);
m_page->setContent(html, mimeType, QUrl::fromLocalFile("/"));
}
void WebEnginePartHtmlEmbedder::startExtractingUrls()
{
+ //Try avoiding problems with redirection (see documentation for this class)
+ disconnect(m_page, &QWebEnginePage::loadFinished, this, &WebEnginePartHtmlEmbedder::startExtractingUrls);
auto lambda = [this](const QVariant &res){emit urlsExtracted(res.toStringList());};
m_page->runJavaScript(s_extractUrlsJs, lambda);
}
@@ -99,7 +102,8 @@
void WebEnginePartHtmlEmbedder::startRetrievingHtml()
{
- m_page->toHtml([this](const QString &html){emit finished(html);});
+ auto callback = [this](const QString &html){emit finished(html);};
+ m_page->toHtml(callback);
}
QString WebEnginePartHtmlEmbedder::dataUrl(const QUrl& url) const
diff --git a/webenginepart/src/webenginepartkiohandler.cpp b/webenginepart/src/webenginepartkiohandler.cpp
--- a/webenginepart/src/webenginepartkiohandler.cpp
+++ b/webenginepart/src/webenginepartkiohandler.cpp
@@ -29,7 +29,6 @@
#include
#include
#include
-#include
#include