mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
WebPage: Add timeout to execJavaScript
This commit is contained in:
parent
36929a45bf
commit
c042d86467
@ -107,15 +107,22 @@ WebView *WebPage::view() const
|
|||||||
return static_cast<WebView*>(QWebEnginePage::view());
|
return static_cast<WebView*>(QWebEnginePage::view());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant WebPage::execJavaScript(const QString &scriptSource)
|
QVariant WebPage::execJavaScript(const QString &scriptSource, int timeout)
|
||||||
{
|
{
|
||||||
QEventLoop loop;
|
QPointer<QEventLoop> loop = new QEventLoop;
|
||||||
QVariant result;
|
QVariant result;
|
||||||
runJavaScript(scriptSource, [&loop, &result](const QVariant &res) {
|
QTimer::singleShot(timeout, loop, &QEventLoop::quit);
|
||||||
result = res;
|
|
||||||
loop.exit();
|
runJavaScript(scriptSource, [loop, &result](const QVariant &res) {
|
||||||
|
if (loop && loop->isRunning()) {
|
||||||
|
result = res;
|
||||||
|
loop->quit();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
loop.exec();
|
|
||||||
|
loop->exec();
|
||||||
|
delete loop;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
|
|
||||||
WebView *view() const;
|
WebView *view() const;
|
||||||
|
|
||||||
QVariant execJavaScript(const QString &scriptSource);
|
QVariant execJavaScript(const QString &scriptSource, int timeout = 500);
|
||||||
|
|
||||||
WebHitTestResult hitTestContent(const QPoint &pos) const;
|
WebHitTestResult hitTestContent(const QPoint &pos) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user