Movatterモバイル変換


[0]ホーム

URL:


Back to Qt.io
Contact UsBlogDownload Qt
Qt documentation

WebEngineScript QML Type

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

Import Statement: import QtWebEngine 1.10
Since: QtWebEngine 1.1
Instantiates:QQuickWebEngineScript

Properties

Detailed Description

The WebEngineScript type enables the programmatic injection of so calleduser scripts in the JavaScript engine at different points, determined byinjectionPoint, during the loading of web content.

Scripts can be executed either in the main JavaScriptworld, 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. TheworldId property provides some predefined IDs for this purpose.

The followingGreasemonkey attributes are supported since Qt 5.8:@exclude,@include,@name,@match, and@run-at.

UseWebEngineView.userScripts 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 isDeferred.

ConstantDescription
WebEngineScript.DocumentCreationThe script will be executed as soon as the document is created. This is not suitable for any DOM operation.
WebEngineScript.DocumentReadyThe script will run as soon as the DOM is ready. This is equivalent to theDOMContentLoaded event firing in JavaScript.
WebEngineScript.DeferredThe 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 fromWebEngineView.userScripts.


runOnSubframes :int

Set this property totrue if the script is executed on every frame in the page, orfalse if it is only ran for the main frame. The default value isfalse.


sourceCode :string

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

See alsosourceUrl.


sourceUrl :url

This property holds the remote source location of the user script (if any).

UnlikesourceCode, this property allows referring to user scripts that are not already loaded in memory, for instance, when stored on disk.

Setting this property will change thesourceCode of the script.

Note:At present, only file-based sources are supported.

See alsosourceCode.


worldId :enumeration

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

ConstantDescription
WebEngineScript.MainWorldThe 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.ApplicationWorldThe default isolated world used for application level functionality implemented in JavaScript.
WebEngineScript.UserWorldThe 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.

© 2025 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 theGNU 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.

Contents

Qt Group includes The Qt Company Oy and its global subsidiaries and affiliates.


[8]ページ先頭

©2009-2025 Movatter.jp