Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


Enables the programmatic injection of scripts in the JavaScript engine. More...

Import Statement: import QtWebEngine
Since: QtWebEngine 1.1
Instantiates: QWebEngineScript


Detailed Description

The WebEngineScript type enables the programmatic injection of so called user scripts in the JavaScript engine at different points, determined by injectionPoint, during the loading of web content.

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. The worldId property provides some predefined IDs for this purpose.

The following Greasemonkey attributes are supported: @exclude, @include, @name, @match, and @run-at.

Use WebEngineScriptCollection to access a list of scripts attached to the web view.

Property Documentation

injectionPoint : enumeration

The point in the loading process at which the script will be executed. The default value is Deferred.

Constant Description
WebEngineScript.DocumentCreation The script will be executed as soon as the document is created. This is not suitable for any DOM operation.
WebEngineScript.DocumentReady The script will run as soon as the DOM is ready. This is equivalent to the DOMContentLoaded event firing in JavaScript.
WebEngineScript.Deferred The script will run when the page load finishes, or 500 ms after the document is ready, whichever comes first.

name : string

The name of the script. Can be useful to retrieve a particular script from WebEngineScriptCollection.find method.

runOnSubframes : int

Set this property to true if the script is executed on every frame in the page, or false if it is only ran for the main frame. The default value is false.

sourceCode : string

This property holds the JavaScript source code of the user script.

See also sourceUrl.

worldId : enumeration

The world ID defining which isolated world the script is executed in.

Constant Description
WebEngineScript.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.
WebEngineScript.ApplicationWorld The default isolated world used for application level functionality implemented in JavaScript.
WebEngineScript.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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded