QWebEngineScript¶
The QWebEngineScript
class encapsulates a JavaScript program. More…
Synopsis¶
Functions¶
def
__eq__
(other)def
__ne__
(other)def
injectionPoint
()def
name
()def
runsOnSubFrames
()def
setInjectionPoint
(arg__1)def
setName
(arg__1)def
setRunsOnSubFrames
(on)def
setSourceCode
(arg__1)def
setSourceUrl
(url)def
setWorldId
(arg__1)def
sourceCode
()def
sourceUrl
()def
swap
(other)def
worldId
()
Detailed Description¶
QWebEngineScript
enables the programmatic injection of so called user scripts in the JavaScript engine at different points, determined by injectionPoint()
, during the loading of web contents.
Scripts can be executed either in the main JavaScript world, along with the rest of the JavaScript coming from the web contents, or in their own isolated world. While the DOM of the page can be accessed from any world, JavaScript variables of a function defined in one world are not accessible from a different one. ScriptWorldId
provides some predefined IDs for this purpose.
The following Greasemonkey attributes are supported since Qt 5.8: @exclude
, @include
, @name
, @match
, and @run-at
.
Use scripts()
and scripts()
to access the collection of scripts associated with a single page or a number of pages sharing the same profile.
See also
- class PySide6.QtWebEngineCore.QWebEngineScript¶
PySide6.QtWebEngineCore.QWebEngineScript(other)
- Parameters
Constructs a null script.
Constructs a user script using the contents of other
.
- PySide6.QtWebEngineCore.QWebEngineScript.InjectionPoint¶
This enum describes the timing of the script injection:
Constant
Description
QWebEngineScript.DocumentCreation
The script will be executed as soon as the document is created. This is not suitable for any DOM operation.
QWebEngineScript.DocumentReady
The script will run as soon as the DOM is ready. This is equivalent to the
DOMContentLoaded
event firing in JavaScript.QWebEngineScript.Deferred
The script will run when the page load finishes, or 500ms after the document is ready, whichever comes first.
- PySide6.QtWebEngineCore.QWebEngineScript.ScriptWorldId¶
This enum provides pre-defined world IDs for isolating user scripts into different worlds:
Constant
Description
QWebEngineScript.MainWorld
The world used by the page’s web contents. It can be useful in order to expose custom functionality to web contents in certain scenarios.
QWebEngineScript.ApplicationWorld
The default isolated world used for application level functionality implemented in JavaScript.
QWebEngineScript.UserWorld
The first isolated world to be used by scripts set by users if the application is not making use of more worlds. As a rule of thumb, if that functionality is exposed to the application users, each individual script should probably get its own isolated world.
- PySide6.QtWebEngineCore.QWebEngineScript.injectionPoint()¶
- Return type
- PySide6.QtWebEngineCore.QWebEngineScript.name()¶
- Return type
str
- PySide6.QtWebEngineCore.QWebEngineScript.__ne__(other)¶
- Parameters
- Return type
bool
Returns true
if the script is not equal to other
, otherwise returns false
.
- PySide6.QtWebEngineCore.QWebEngineScript.__eq__(other)¶
- Parameters
- Return type
bool
Returns true
if the script is equal to other
, otherwise returns false
.
- PySide6.QtWebEngineCore.QWebEngineScript.runsOnSubFrames()¶
- Return type
bool
- PySide6.QtWebEngineCore.QWebEngineScript.setInjectionPoint(arg__1)¶
- Parameters
arg__1 –
InjectionPoint
- PySide6.QtWebEngineCore.QWebEngineScript.setName(arg__1)¶
- Parameters
arg__1 – str
- PySide6.QtWebEngineCore.QWebEngineScript.setRunsOnSubFrames(on)¶
- Parameters
on – bool
- PySide6.QtWebEngineCore.QWebEngineScript.setSourceCode(arg__1)¶
- Parameters
arg__1 – str
- PySide6.QtWebEngineCore.QWebEngineScript.setSourceUrl(url)¶
- Parameters
url –
PySide6.QtCore.QUrl
- PySide6.QtWebEngineCore.QWebEngineScript.setWorldId(arg__1)¶
- Parameters
arg__1 – int
- PySide6.QtWebEngineCore.QWebEngineScript.sourceCode()¶
- Return type
str
- PySide6.QtWebEngineCore.QWebEngineScript.sourceUrl()¶
- Return type
- PySide6.QtWebEngineCore.QWebEngineScript.swap(other)¶
- Parameters
Swaps the contents of the script with the contents of other
.
- PySide6.QtWebEngineCore.QWebEngineScript.worldId()¶
- Return type
int
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.