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());
|
||||
}
|
||||
|
||||
QVariant WebPage::execJavaScript(const QString &scriptSource)
|
||||
QVariant WebPage::execJavaScript(const QString &scriptSource, int timeout)
|
||||
{
|
||||
QEventLoop loop;
|
||||
QPointer<QEventLoop> loop = new QEventLoop;
|
||||
QVariant result;
|
||||
runJavaScript(scriptSource, [&loop, &result](const QVariant &res) {
|
||||
QTimer::singleShot(timeout, loop, &QEventLoop::quit);
|
||||
|
||||
runJavaScript(scriptSource, [loop, &result](const QVariant &res) {
|
||||
if (loop && loop->isRunning()) {
|
||||
result = res;
|
||||
loop.exit();
|
||||
loop->quit();
|
||||
}
|
||||
});
|
||||
loop.exec();
|
||||
|
||||
loop->exec();
|
||||
delete loop;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
|
||||
WebView *view() const;
|
||||
|
||||
QVariant execJavaScript(const QString &scriptSource);
|
||||
QVariant execJavaScript(const QString &scriptSource, int timeout = 500);
|
||||
|
||||
WebHitTestResult hitTestContent(const QPoint &pos) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user