How to declare WebEngineScripts and use them in a WebEngineView in Qt6
-
The documentation does not make sufficiently clear how to create WebEngineScripts and WebEngineScriptCollections in Qt6. For example, how would this QML be ported to Qt6, where WebEngineScript is non-creatable.
WebEngineView { id: web objectName: "web" settings.errorPageEnabled: false settings.localContentCanAccessRemoteUrls: true profile.httpUserAgent: components.system.getUserAgent() url: mainWindow.webUrl focus: true property string currentHoveredUrl: "" onLinkHovered: web.currentHoveredUrl = hoveredUrl width: mainWindow.width height: mainWindow.height userScripts: [ WebEngineScript { sourceCode: components.system.getNativeShellScript(), injectionPoint: WebEngineScript.DocumentCreation, worldId: WebEngineScript.MainWorld } ] ...
-
The documentation does not make sufficiently clear how to create WebEngineScripts and WebEngineScriptCollections in Qt6. For example, how would this QML be ported to Qt6, where WebEngineScript is non-creatable.
WebEngineView { id: web objectName: "web" settings.errorPageEnabled: false settings.localContentCanAccessRemoteUrls: true profile.httpUserAgent: components.system.getUserAgent() url: mainWindow.webUrl focus: true property string currentHoveredUrl: "" onLinkHovered: web.currentHoveredUrl = hoveredUrl width: mainWindow.width height: mainWindow.height userScripts: [ WebEngineScript { sourceCode: components.system.getNativeShellScript(), injectionPoint: WebEngineScript.DocumentCreation, worldId: WebEngineScript.MainWorld } ] ...
The solution to this problem is well documented, my issue was just getting a search engine to show me this document:
https://doc.qt.io/qt-6/qml-qtwebengine-webenginescriptcollection.html