Skip to content

Commit 002e476

Browse files
Doc: Edit docs on script injection
Task-number: QTBUG-76489 Change-Id: If489ebed802d273b0015bc6cfc190d948c4896e3 Reviewed-by: Jüri Valdmann <[email protected]>
1 parent 662de14 commit 002e476

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

src/webengine/doc/src/webengineview_lgpl.qdoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@
396396
runJavaScript("document.title", function(result) { console.log(result); });
397397
\endcode
398398

399-
Only "plain data" can be returned from JavaScript as the result value.
399+
Only plain data can be returned from JavaScript as the result value.
400400
Supported data types include all of the JSON data types as well as, for
401401
example, \c{Date} and \c{ArrayBuffer}. Unsupported data types include, for
402402
example, \c{Function} and \c{Promise}.
@@ -407,7 +407,8 @@
407407
\warning Do not execute lengthy routines in the callback function, because it might block the
408408
rendering of the web content.
409409

410-
See WebEngineView::userScripts for an alternative API to inject scripts.
410+
For more information about injecting scripts, see \l {Script Injection}.
411+
For an alternative way to inject scripts, see WebEngineView::userScripts.
411412
*/
412413

413414
/*!

src/webenginewidgets/api/qwebenginepage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ void QWebEnginePage::runJavaScript(const QString& scriptSource, quint32 worldId,
21832183
In addition, a page might also execute scripts
21842184
added through QWebEngineProfile::scripts().
21852185
2186-
\sa QWebEngineScriptCollection, QWebEngineScript
2186+
\sa QWebEngineScriptCollection, QWebEngineScript, {Script Injection}
21872187
*/
21882188

21892189
QWebEngineScriptCollection &QWebEnginePage::scripts()

src/webenginewidgets/api/qwebengineprofile.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ bool QWebEngineProfile::visitedLinksContainsUrl(const QUrl &url) const
593593
Returns the collection of scripts that are injected into all pages that share
594594
this profile.
595595
596-
\sa QWebEngineScriptCollection, QWebEngineScript, QWebEnginePage::scripts()
596+
\sa QWebEngineScriptCollection, QWebEngineScript, QWebEnginePage::scripts(),
597+
{Script Injection}
597598
*/
598599
QWebEngineScriptCollection *QWebEngineProfile::scripts() const
599600
{

src/webenginewidgets/api/qwebenginescript.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ using QtWebEngineCore::UserScript;
6767
Use QWebEnginePage::scripts() and QWebEngineProfile::scripts() to access
6868
the collection of scripts associated with a single page or a
6969
number of pages sharing the same profile.
70+
71+
\sa {Script Injection}
7072
*/
7173
/*!
7274
\enum QWebEngineScript::InjectionPoint

src/webenginewidgets/api/qwebenginescriptcollection.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ using QtWebEngineCore::UserScript;
5555
Use QWebEnginePage::scripts() and QWebEngineProfile::scripts() to access
5656
the collection of scripts associated with a single page or a
5757
number of pages sharing the same profile.
58+
59+
\sa {Script Injection}
5860
*/
5961

6062
/*!

src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,15 @@
759759
\fn void QWebEnginePage::runJavaScript(const QString &scriptSource, const QWebEngineCallback<const QVariant &> &resultCallback)
760760
\since 5.7
761761

762-
Runs the JavaScript code contained in \a scriptSource in the world specified by \a worldId.
763-
The world ID values are the same as provided by QWebEngineScript::ScriptWorldId, and between \c 0
764-
and \c 256. Using the \e runJavaScript() versions without the world ID is the same as running the
765-
script in the \c MainWorld.
762+
Runs the JavaScript code contained in \a scriptSource without checking
763+
whether the DOM of the page has been constructed. If you need more
764+
control over how the script is run, consider using \l scripts() instead.
765+
766+
To avoid conflicts with other scripts executed on the page, the world in
767+
which the script is run is specified by \a worldId. The world ID values are
768+
the same as provided by QWebEngineScript::ScriptWorldId, and between \c 0
769+
and \c 256. If you leave out the \c world ID, the script is run in the
770+
\c MainWorld.
766771

767772
When the script has been executed, \a resultCallback is called with the result of the last
768773
executed statement. \c resultCallback can be any of a function pointer, a functor or a lambda,
@@ -772,7 +777,7 @@
772777
page.runJavaScript("document.title", [](const QVariant &v) { qDebug() << v.toString(); });
773778
\endcode
774779

775-
Only "plain data" can be returned from JavaScript as the result value.
780+
Only plain data can be returned from JavaScript as the result value.
776781
Supported data types include all of the JSON data types as well as, for
777782
example, \c{Date} and \c{ArrayBuffer}. Unsupported data types include, for
778783
example, \c{Function} and \c{Promise}.
@@ -784,9 +789,7 @@
784789
during page destruction. When QWebEnginePage is deleted, the callback is triggered with an invalid
785790
value and it is not safe to use the corresponding QWebEnginePage or QWebEngineView instance inside it.
786791

787-
See scripts() for an alternative API to inject scripts.
788-
789-
\sa QWebEngineScript::ScriptWorldId
792+
\sa scripts(), QWebEngineScript::ScriptWorldId, {Script Injection}
790793
*/
791794

792795
/*!

0 commit comments

Comments
 (0)