PySide6.QtWebEngineCore.QWebEnginePage¶
- class QWebEnginePage¶
The
QWebEnginePage
class provides an object to view and edit web documents. More…Synopsis¶
Properties¶
audioMutedᅟ
- Whether the current page audio is mutedbackgroundColorᅟ
- Page’s background color behind the document’s bodycontentsSizeᅟ
- Size of the page contentshasSelectionᅟ
- Whether this page contains selected content or noticonᅟ
- Associated with the page currently viewediconUrlᅟ
- URL of the icon associated with the page currently viewedlifecycleStateᅟ
- Current lifecycle state of the pageloadingᅟ
- Whether the page is currently loadingrecentlyAudibleᅟ
- Current page’s audible state, that is, whether audio was recently played or notrecommendedStateᅟ
- Recommended limit for the lifecycle state of the pagerenderProcessPidᅟ
- Process ID (PID) of the render process assigned to the current page’s main framerequestedUrlᅟ
- URL that was originally requested to be loaded by the page that is currently viewedscrollPositionᅟ
- Scroll position of the page contentsselectedTextᅟ
- Text currently selectedtitleᅟ
- Of the page as defined by the HTML <title> elementurlᅟ
- URL of the page currently viewedvisibleᅟ
- Whether the page is considered visible in the Page Visibility APIzoomFactorᅟ
- Zoom factor for the page content
Methods¶
def
__init__()
def
action()
def
contentsSize()
def
devToolsId()
def
devToolsPage()
def
download()
def
findText()
def
hasSelection()
def
history()
def
icon()
def
iconUrl()
def
inspectedPage()
def
isAudioMuted()
def
isLoading()
def
isVisible()
def
lifecycleState()
def
load()
def
mainFrame()
def
printToPdf()
def
profile()
def
requestedUrl()
def
runJavaScript()
def
save()
def
scripts()
def
scrollPosition()
def
selectedText()
def
setAudioMuted()
def
setContent()
def
setHtml()
def
setUrl()
def
setVisible()
def
setWebChannel()
def
setZoomFactor()
def
settings()
def
title()
def
toHtml()
def
toPlainText()
def
url()
def
webChannel()
def
zoomFactor()
Virtual methods¶
def
chooseFiles()
def
createWindow()
def
triggerAction()
Signals¶
def
iconChanged()
def
iconUrlChanged()
def
linkHovered()
def
loadFinished()
def
loadProgress()
def
loadStarted()
def
loadingChanged()
def
printRequested()
def
quotaRequested()
def
titleChanged()
def
urlChanged()
def
visibleChanged()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
A web engine page holds the contents of an HTML document, the history of navigated links, and actions.
QWebEnginePage
‘s API is very similar toQWebEngineView
, as you are still provided with common functions likeaction()
(known aspageAction
() inQWebEngineView
),triggerAction()
, andfindText()
.A page can be loaded using
load()
orsetUrl()
. Alternatively, if you have the HTML content readily available, you can usesetHtml()
. The GET method is always used to load URLs.The
QWebEnginePage
class also offers methods to retrieve both the URL currently loaded by the page (seeurl()
) as well as the URL originally requested to be loaded (seerequestedUrl()
). These methods make possible the retrieval of the URL before and after a DNS resolution or a redirection occurs during the load process. TherequestedUrl()
also matches to the URL added to the page history (QWebEngineHistory
) if load is successful.The title of an HTML page can be accessed with the
title()
property. Additionally, a page may also specify an icon, which can be accessed using theicon()
or its URL using theiconUrl()
property. If the title or the icon changes, the correspondingtitleChanged()
,iconChanged()
andiconUrlChanged()
signals will be emitted. ThezoomFactor()
property enables zooming the contents of the web page by a scale factor.The
loadStarted()
signal is emitted when the page begins to load, whereas theloadProgress()
signal is emitted whenever an element of the web page completes loading, such as an embedded image or a script. TheloadFinished()
signal is emitted when the page contents have been loaded completely, independent of script execution or page rendering. Its argument, eithertrue
orfalse
, indicates whether or not the load operation succeeded.An HTML document is loaded in a main frame within the web page. If it references child frames (as defined by the
<frame>
or<iframe>
elements), they are considered part of the content. Child frames are individually accessible only through JavaScript.Web sites define security origin for safely accessing each other’s resources for client-side scripting or databases. An origin consist of a host name, a scheme, and a port number. For example, the sites
http://www.example.com/my/page.html
andhttp://www.example.com/my/overview.html
are allowed to share the same database or access each other’s documents when used in HTML frame sets and JavaScript. At the same time,http://www.malicious.com/evil.html
is prevented from accessing the resources ofhttp://www.example.com/
, because they are of a different security origin. By default, local schemes likefile://
andqrc://
are considered to be in the same security origin, and can access each other’s resources. Local resources are by default restricted from accessing remote content, which means thatfile://
will not be able to accesshttp://domain.com/foo.html
.Scripts can be executed on the web page by using
runJavaScript()
, 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. Using therunJavaScript()
version without the world ID is the same as running the script in theMainWorld
.The
FocusOnNavigationEnabled
setting can be used to make the view associated with the page automatically receive focus when a navigation operation occurs (like loading or reloading a page or navigating through history).- class WebAction¶
This enum describes the types of action which can be performed on the web page.
Actions only have an effect when they are applicable.
The availability of actions can be be determined by checking isEnabled() on the action returned by
action()
.Constant
Description
QWebEnginePage.NoWebAction
No action is triggered.
QWebEnginePage.Back
Navigate back in the history of navigated links.
QWebEnginePage.Forward
Navigate forward in the history of navigated links.
QWebEnginePage.Stop
Stop loading the current page.
QWebEnginePage.Reload
Reload the current page.
QWebEnginePage.ReloadAndBypassCache
Reload the current page, but do not use any local cache.
QWebEnginePage.Cut
Cut the content currently selected into the clipboard.
QWebEnginePage.Copy
Copy the content currently selected into the clipboard.
QWebEnginePage.Paste
Paste content from the clipboard.
QWebEnginePage.Undo
Undo the last editing action.
QWebEnginePage.Redo
Redo the last editing action.
QWebEnginePage.SelectAll
Select all content. This action is only enabled when the page’s content is focused. The focus can be forced by the JavaScript
window.focus()
call, or theFocusOnNavigationEnabled
setting should be enabled to get automatic focus.QWebEnginePage.PasteAndMatchStyle
Paste content from the clipboard with current style.
QWebEnginePage.OpenLinkInThisWindow
Open the current link in the current window.
QWebEnginePage.OpenLinkInNewWindow
Open the current link in a new window. Requires implementation of
createWindow()
ornewWindowRequested()
.QWebEnginePage.OpenLinkInNewTab
Open the current link in a new tab. Requires implementation of
createWindow()
ornewWindowRequested()
.QWebEnginePage.OpenLinkInNewBackgroundTab
Open the current link in a new background tab. Requires implementation of
createWindow()
ornewWindowRequested()
.QWebEnginePage.CopyLinkToClipboard
Copy the current link to the clipboard.
QWebEnginePage.CopyImageToClipboard
Copy the clicked image to the clipboard.
QWebEnginePage.CopyImageUrlToClipboard
Copy the clicked image’s URL to the clipboard.
QWebEnginePage.CopyMediaUrlToClipboard
Copy the hovered audio or video’s URL to the clipboard.
QWebEnginePage.ToggleMediaControls
Toggle between showing and hiding the controls for the hovered audio or video element.
QWebEnginePage.ToggleMediaLoop
Toggle whether the hovered audio or video should loop on completetion or not.
QWebEnginePage.ToggleMediaPlayPause
Toggle the play/pause state of the hovered audio or video element.
QWebEnginePage.ToggleMediaMute
Mute or unmute the hovered audio or video element.
QWebEnginePage.DownloadLinkToDisk
Download the current link to the disk. Requires a slot for
downloadRequested()
.QWebEnginePage.DownloadImageToDisk
Download the highlighted image to the disk. Requires a slot for
downloadRequested()
.QWebEnginePage.DownloadMediaToDisk
Download the hovered audio or video to the disk. Requires a slot for
downloadRequested()
.QWebEnginePage.InspectElement
Trigger any attached Web Inspector to inspect the highlighed element.
QWebEnginePage.ExitFullScreen
Exit the fullscreen mode.
QWebEnginePage.RequestClose
Request to close the web page. If defined, the
window.onbeforeunload
handler is run, and the user can confirm or reject to close the page. If the close request is confirmed,windowCloseRequested
is emitted.QWebEnginePage.Unselect
Clear the current selection.
QWebEnginePage.SavePage
Save the current page to disk. MHTML is the default format that is used to store the web page on disk. Requires a slot for
downloadRequested()
.QWebEnginePage.ViewSource
Show the source of the current page in a new tab. Requires implementation of
createWindow()
ornewWindowRequested()
.QWebEnginePage.ToggleBold
Toggles boldness for the selection or at the cursor position. Requires
contenteditable="true"
.QWebEnginePage.ToggleItalic
Toggles italics for the selection or at the cursor position. Requires
contenteditable="true"
.QWebEnginePage.ToggleUnderline
Toggles underlining of the selection or at the cursor position. Requires
contenteditable="true"
.QWebEnginePage.ToggleStrikethrough
Toggles striking through the selection or at the cursor position. Requires
contenteditable="true"
.QWebEnginePage.AlignLeft
Aligns the lines containing the selection or the cursor to the left. Requires
contenteditable="true"
.QWebEnginePage.AlignCenter
Aligns the lines containing the selection or the cursor at the center. Requires
contenteditable="true"
.QWebEnginePage.AlignRight
Aligns the lines containing the selection or the cursor to the right. Requires
contenteditable="true"
.QWebEnginePage.AlignJustified
Stretches the lines containing the selection or the cursor so that each line has equal width. Requires
contenteditable="true"
.QWebEnginePage.Indent
Indents the lines containing the selection or the cursor. Requires
contenteditable="true"
.QWebEnginePage.Outdent
Outdents the lines containing the selection or the cursor. Requires
contenteditable="true"
.QWebEnginePage.InsertOrderedList
Inserts an ordered list at the current cursor position, deleting the current selection. Requires
contenteditable="true"
.QWebEnginePage.InsertUnorderedList
Inserts an unordered list at the current cursor position, deleting the current selection. Requires
contenteditable="true"
.QWebEnginePage.ChangeTextDirectionLTR
Changes text direction to left-to-right in the focused input element.
QWebEnginePage.ChangeTextDirectionRTL
Changes text direction to right-to-left in the focused input element.
- class FindFlag¶
(inherits
enum.Flag
) This enum describes the options available to thefindText()
function. The options can be OR-ed together from the following list:Constant
Description
QWebEnginePage.FindBackward
Searches backwards instead of forwards.
QWebEnginePage.FindCaseSensitively
By default
findText()
works case insensitive. Specifying this option changes the behavior to a case sensitive find operation.
- class WebWindowType¶
This enum describes the types of window that can be created by the
createWindow()
function:Constant
Description
QWebEnginePage.WebBrowserWindow
A complete web browser window.
QWebEnginePage.WebBrowserTab
A web browser tab.
QWebEnginePage.WebDialog
A window without decoration.
QWebEnginePage.WebBrowserBackgroundTab
A web browser tab without hiding the current visible WebEngineView .
- class PermissionPolicy¶
Replaced by
State
.This enum describes the permission policies that the user may set for data or device access:
Constant
Description
QWebEnginePage.PermissionUnknown
It is unknown whether the user grants or denies permission.
QWebEnginePage.PermissionGrantedByUser
The user has granted permission.
QWebEnginePage.PermissionDeniedByUser
The user has denied permission.
This enum describes the type of a navigation request:
Constant
Description
QWebEnginePage.NavigationTypeLinkClicked
The navigation request resulted from a clicked link.
QWebEnginePage.NavigationTypeTyped
The navigation request resulted from an explicitly loaded URL.
QWebEnginePage.NavigationTypeFormSubmitted
The navigation request resulted from a form submission.
QWebEnginePage.NavigationTypeBackForward
The navigation request resulted from a back or forward action.
QWebEnginePage.NavigationTypeReload
The navigation request resulted from a reload action.
QWebEnginePage.NavigationTypeRedirect
The navigation request resulted from a content or server controlled redirect. This also includes automatic reloads.
QWebEnginePage.NavigationTypeOther
The navigation request was triggered by other means not covered by the above.
See also
- class Feature¶
Replaced by QWebEnginePermission::Feature.
This enum describes the platform feature access categories that the user may be asked to grant or deny access to:
Constant
Description
QWebEnginePage.Notifications
Web notifications for the end-user.
QWebEnginePage.Geolocation
Location hardware or service.
QWebEnginePage.MediaAudioCapture
Audio capture devices, such as microphones.
QWebEnginePage.MediaVideoCapture
Video devices, such as cameras.
QWebEnginePage.MediaAudioVideoCapture
Both audio and video capture devices.
QWebEnginePage.MouseLock
Mouse locking, which locks the mouse pointer to the web view and is typically used in games.
QWebEnginePage.DesktopVideoCapture
Video output capture, that is, the capture of the user’s display, for screen sharing purposes for example.
QWebEnginePage.DesktopAudioVideoCapture
Both audio and video output capture.
QWebEnginePage.ClipboardReadWrite
Read and write access for the clipboard. If both
JavascriptCanPaste
andJavascriptCanAccessClipboard
settings are enabled, this permission will always be granted automatically and no feature requests will be made.QWebEnginePage.LocalFontsAccess
Access to the fonts installed on the user’s machine. Only available on desktop platforms.
- class FileSelectionMode¶
This enum indicates whether the implementation of the
chooseFiles()
function should return only one file or may return multiple files:Constant
Description
QWebEnginePage.FileSelectOpen
Return only one file name.
QWebEnginePage.FileSelectOpenMultiple
Return multiple file names.
QWebEnginePage.FileSelectUploadFolder
Allows users to specify a single existing folder for upload.
QWebEnginePage.FileSelectSave
Specify a new file to be created.
See also
- class JavaScriptConsoleMessageLevel¶
This enum describes the different severity levels a JavaScript console message can have:
Constant
Description
QWebEnginePage.InfoMessageLevel
The message is purely informative and can safely be ignored.
QWebEnginePage.WarningMessageLevel
The message informs about unexpected behavior or errors that may need attention.
QWebEnginePage.ErrorMessageLevel
The message indicates there has been an error.
- class RenderProcessTerminationStatus¶
This enum describes the status with which the render process terminated:
Constant
Description
QWebEnginePage.NormalTerminationStatus
The render process terminated normally.
QWebEnginePage.AbnormalTerminationStatus
The render process terminated with with a non-zero exit status.
QWebEnginePage.CrashedTerminationStatus
The render process crashed, for example because of a segmentation fault.
QWebEnginePage.KilledTerminationStatus
The render process was killed, for example by
SIGKILL
or task manager kill.
- class LifecycleState¶
This enum describes the lifecycle state of the page:
Constant
Description
QWebEnginePage.LifecycleState.Active
Normal state.
QWebEnginePage.LifecycleState.Frozen
Low CPU usage state where most HTML task sources are suspended.
QWebEnginePage.LifecycleState.Discarded
Very low resource usage state where the entire browsing context is discarded.
See also
lifecycleState
Page Lifecycle API WebEngine Lifecycle Example
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property audioMutedᅟ: bool¶
This property holds Whether the current page audio is muted..
The default value is
false
.See also
- Access functions:
This property holds The page’s background color behind the document’s body..
You can set the background color to Qt::transparent or to a translucent color to see through the document, or you can set it to match your web content in a hybrid application to prevent the white flashes that may appear during loading.
The default value is white.
- Access functions:
This property holds The size of the page contents..
- Access functions:
- property hasSelectionᅟ: bool¶
This property holds Whether this page contains selected content or not..
See also
- Access functions:
This property holds The icon associated with the page currently viewed..
By default, this property contains a null icon. If touch icons are disabled (see
QWebEngineSettings::TouchIconsEnabled
), the favicon is provided in two sizes (16x16 and 32x32 pixels) encapsulated inQIcon
. Otherwise, single icon is provided with the largest available size.- Access functions:
Signal
iconChanged()
This property holds The URL of the icon associated with the page currently viewed..
By default, this property contains an empty URL.
See also
- Access functions:
Signal
iconUrlChanged()
- property lifecycleStateᅟ: QWebEnginePage.LifecycleState¶
This property holds The current lifecycle state of the page..
The following restrictions are enforced by the setter:
A
visible
page must remain in theActive
state.If the page is being inspected by a
devToolsPage
then both pages must remain in theActive
states.A page in the
Discarded
state can only transition to theActive
state. This will cause a reload of the page.
These are the only hard limits on the lifecycle state, but see also
recommendedState
for the recommended soft limits.See also
recommendedState
Page Lifecycle API WebEngine Lifecycle Example- Access functions:
- property loadingᅟ: bool¶
This property holds Whether the page is currently loading..
See also
- Access functions:
Signal
loadingChanged()
- property recentlyAudibleᅟ: bool¶
This property holds The current page’s audible state, that is, whether audio was recently played or not..
The default value is
false
.See also
audioMuted
- Access functions:
- property recommendedStateᅟ: QWebEnginePage.LifecycleState¶
This property holds The recommended limit for the lifecycle state of the page..
Setting the lifecycle state to a lower resource usage state than the recommended state may cause side-effects such as stopping background audio playback or loss of HTML form input. Setting the lifecycle state to a higher resource state is however completely safe.
See also
lifecycleState
Page Lifecycle API WebEngine Lifecycle Example- Access functions:
- property renderProcessPidᅟ: int¶
This property holds The process ID (PID) of the render process assigned to the current page’s main frame..
If no render process is available yet,
0
is returned.- Access functions:
This property holds The URL that was originally requested to be loaded by the page that is currently viewed..
Note
The URL may differ from the one returned by
url()
, which is the actual URL that results from DNS resolution or redirection.- Access functions:
This property holds The scroll position of the page contents..
- Access functions:
- property selectedTextᅟ: str¶
This property holds The text currently selected..
By default, this property contains an empty string.
See also
- Access functions:
- property titleᅟ: str¶
This property holds The title of the page as defined by the HTML
<title>
element..If the page has no
<title>
element, then the URL is used instead. Forfile://
URLs only the filename is used and not the full path.By default, before any content has been loaded, this property contains an empty string.
See also
- Access functions:
Signal
titleChanged()
This property holds The URL of the page currently viewed..
Setting this property clears the view and loads the URL.
By default, this property contains an empty, invalid URL.
See also
- Access functions:
Signal
urlChanged()
- property visibleᅟ: bool¶
This property holds Whether the page is considered visible in the Page Visibility API..
Setting this property changes the
Document.hidden
and theDocument.visibilityState
properties in JavaScript which web sites can use to voluntarily reduce their resource usage if they are not visible to the user.If the page is connected to a view then this property will be managed automatically by the view according to it’s own visibility.
See also
- Access functions:
- property zoomFactorᅟ: float¶
This property holds The zoom factor for the page content..
Valid values are within the range from
0.25
to5.0
. The default factor is1.0
.See also
- Access functions:
Constructs an empty
QWebEnginePage
with the parentparent
.- __init__(profile[, parent=None])
- Parameters:
profile –
QWebEngineProfile
parent –
QObject
Constructs an empty web engine page in the web engine profile
profile
with the parentparent
.If the profile is not the default profile, the caller must ensure that the profile stays alive for as long as the page does.
- _q_aboutToDelete()¶
- acceptAsNewWindow(request)¶
- Parameters:
request –
QWebEngineNewWindowRequest
- Parameters:
url –
QUrl
type –
NavigationType
isMainFrame – bool
- Return type:
bool
This function is called upon receiving a request to navigate to the specified
url
by means of the specified navigation typetype
.isMainFrame
indicates whether the request corresponds to the main frame or a child frame. If the function returnstrue
, the navigation request is accepted andurl
is loaded. The default implementation accepts all navigation requests.Navigation requests can be delegated to the Qt application instead of having the HTML handler engine process them by overloading this function. This is necessary when an HTML document is used as part of the user interface, and not to display external data, for example, when displaying a list of results.
Note
This function is not called for fragment navigation on the same page. Such navigation, for example, happens by clicking a link to a ‘#fragment’ within the page. It does not trigger a load to a different document, even though it changes page’s url and adds history entry. It only serves as a shortcut to scroll within the page. Hence, no delegation of this navigation type is expected to happen.
Note
The loading process is started and the
loadStarted()
signal is emitted before the request is accepted or rejected. Therefore, aloadFinished()
signal that returnsfalse
is to be expected even after delegating the request.Note
When using
setHtml
orsetContent
with relative links, make sure to specify a base url, otherwise the links will be considered invalid and no navigation requests will be emitted.The
QWebEngineUrlRequestInterceptor
class offers further options for intercepting and manipulating requests.Returns a QAction for the specified
WebAction
action
.The action is owned by the
QWebEnginePage
but you can customize the look by changing its properties.The returned action does not have a default styled icon. Use
pageAction()
to have an action with a default styled icon.QWebEnginePage
also takes care of implementing the action, so that upon triggering the corresponding action is performed on the page.See also
- audioMutedChanged(muted)¶
- Parameters:
muted – bool
This signal is emitted when the page’s
muted
state changes.Note
Not to be confused with a specific HTML5 audio or video element being muted.
Notification signal of property
audioMutedᅟ
.- authenticationRequired(requestUrl, authenticator)¶
- Parameters:
requestUrl –
QUrl
authenticator –
QAuthenticator
This signal is emitted when access to
requestUrl
requires authentication.authenticator
should be used to pass the user name and password for the connection.- backgroundColor()¶
- Return type:
See also
Getter of property
backgroundColorᅟ
.- certificateError(certificateError)¶
- Parameters:
certificateError –
QWebEngineCertificateError
This signal is emitted when an invalid certificate error is raised while loading a given request.
The
certificateError
parameter contains information about the certificate and details of the error, it also provides the way to ignore the error and complete the request or stop loading the request.See also
- chooseFiles(mode, oldFiles, acceptedMimeTypes)¶
- Parameters:
mode –
FileSelectionMode
oldFiles – list of strings
acceptedMimeTypes – list of strings
- Return type:
list of strings
This function is called when the web content requests a file name, for example as a result of the user clicking on a file upload button in an HTML form.
mode
indicates whether only one file or multiple files are expected to be returned.A suggested filename may be provided as the first entry of
oldFiles
.acceptedMimeTypes
is ignored by the default implementation, but might be used by overrides.Getter of property
contentsSizeᅟ
.Notification signal of property
contentsSizeᅟ
.- createWindow(type)¶
- Parameters:
type –
WebWindowType
- Return type:
This function is called to create a new window of the specified
type
. For example, when a JavaScript program requests to open a document in a new window.If the new window can be created, the new window’s
QWebEnginePage
is returned; otherwise a null pointer is returned.If the view associated with the web page is a
QWebEngineView
object, then the default implementation forwards the request tocreateWindow()
; otherwise it returns a null pointer.If this call is not implemented or does not return a new page,
newWindowRequested()
is emitted to handle the request.Note
In the cases when the window creation is being triggered by JavaScript, apart from reimplementing this method the application must also set
JavascriptCanOpenWindows
totrue
in order for the method to get called.See also
- devToolsId()¶
- Return type:
str
Returns the id of the developer tools host associated with this page.
If remote debugging is enabled (see Qt WebEngine Developer Tools ), the id can be used to build the URL to connect to the developer tool websocket:
ws://localhost:<debugggin-port>/devtools/page/<id>)
. The websocket can be used to to interact with the page using the DevTools Protocol .- devToolsPage()¶
- Return type:
Returns the page that is hosting the developer tools of this page, if any.
Returns
nullptr
if no developer tools page is set.See also
Downloads the resource from the location given by
url
to a local file.If
filename
is given, it is used as the suggested file name. If it is relative, the file is saved in the standard download location with the given name. If it is a null or empty QString, the default file name is used.This will emit
downloadRequested()
after the download has started.- featurePermissionRequestCanceled(securityOrigin, feature)¶
-
Note
This function is deprecated.
This signal is no longer emitted.
This signal is emitted when the web site identified by
securityOrigin
cancels a previously issued request to make use offeature
.- featurePermissionRequested(securityOrigin, feature)¶
-
Note
This function is deprecated.
Use
permissionRequested()
instead.This signal is emitted when the web site identified by
securityOrigin
requests to make use of the resource or device identified byfeature
.- fileSystemAccessRequested(request)¶
- Parameters:
request –
QWebEngineFileSystemAccessRequest
This signal is emitted when the web page requests access to local files or directories.
The request object
request
can be used to accept or reject the request.- findFrameByName(name)¶
- Parameters:
name – str
- Return type:
Returns the frame with the given
name
. If there are multiple frames with the same name, which one is returned is arbitrary. If no frame was found, returnsNone
.- findText(subString, options, resultCallback)
- Parameters:
subString – str
options – Combination of
FindFlag
resultCallback –
PyCallable
Finds the specified string,
subString
, in the page, using the givenoptions
. ThefindTextFinished()
signal is emitted when a string search is completed.To clear the search highlight, just pass an empty string.
The
resultCallback
must take aQWebEngineFindTextResult
parameter.Note
We guarantee that the
resultCallback
is always called, but it might be done during page destruction. WhenQWebEnginePage
is deleted, the callback is triggered with an invalid value and it is not safe to use the correspondingQWebEnginePage
,QWebEngineFrame
, orQWebEngineView
instance inside it.- findTextFinished(result)¶
- Parameters:
result –
QWebEngineFindTextResult
This signal is emitted when a search string search on a page is completed.
result
is the result of the string search.See also
- fullScreenRequested(fullScreenRequest)¶
- Parameters:
fullScreenRequest –
QWebEngineFullScreenRequest
This signal is emitted when the web page issues the request to enter fullscreen mode for a web-element, usually a video element.
The request object
fullScreenRequest
can be used to accept or reject the request.If the request is accepted the element requesting fullscreen will fill the viewport, but it is up to the application to make the view fullscreen or move the page to a view that is fullscreen.
See also
This signal is emitted whenever the document wants to change the position and size of the page to
geom
. This can happen for example through JavaScript.Note
setGeometry() expects a size excluding the window decoration, while
geom
includes it. You have to remove the size of the frame margins fromgeom
to handle this signal correctly.window->setGeometry(geom.marginsRemoved(window->frameMargins()));
- hasSelection()¶
- Return type:
bool
Getter of property
hasSelectionᅟ
.- history()¶
- Return type:
Returns a pointer to the view’s history of navigated web pages.
Getter of property
iconᅟ
.This signal is emitted when the icon (“favicon”) associated with the page is changed. The new icon is specified by
icon
.See also
Notification signal of property
iconᅟ
.Getter of property
iconUrlᅟ
.This signal is emitted when the URL of the icon (“favicon”) associated with the page is changed. The new URL is specified by
url
.See also
Notification signal of property
iconUrlᅟ
.- inspectedPage()¶
- Return type:
Returns the page this page is inspecting, if any.
Returns
nullptr
if this page is not a developer tools page.See also
- isAudioMuted()¶
- Return type:
bool
Getter of property
audioMutedᅟ
.- isLoading()¶
- Return type:
bool
Getter of property
loadingᅟ
.- isVisible()¶
- Return type:
bool
Getter of property
visibleᅟ
.This function is called whenever a JavaScript program running in a frame affiliated with
securityOrigin
calls thealert()
function with the messagemsg
.The default implementation shows the message,
msg
, with QMessageBox::information.- javaScriptConfirm(securityOrigin, msg)¶
- Parameters:
securityOrigin –
QUrl
msg – str
- Return type:
bool
This function is called whenever a JavaScript program running in a frame affiliated with
securityOrigin
calls theconfirm()
function with the messagemsg
. Returnstrue
if the user confirms the message; otherwise returnsfalse
.It is also called when the
onbeforeunload
handler is requesting a confirmation before leaving a page.The default implementation executes the query using QMessageBox::information with QMessageBox::Ok and QMessageBox::Cancel buttons.
- javaScriptConsoleMessage(level, message, lineNumber, sourceID)¶
- Parameters:
level –
JavaScriptConsoleMessageLevel
message – str
lineNumber – int
sourceID – str
This function is called when a JavaScript program tries to print the
message
to the web browser’s console.For example, in case of evaluation errors the source URL may be provided in
sourceID
as well as thelineNumber
.level
indicates the severity of the event that triggered the message. That is, whether it was triggered by an error or a less severe event.Since Qt 5.6, the default implementation logs the messages in a
js
logging category.See also
Console Logging
- javaScriptPrompt(securityOrigin, msg, defaultValue)¶
- Parameters:
securityOrigin –
QUrl
msg – str
defaultValue – str
- Return type:
bool
This function is called whenever a JavaScript program running in a frame affiliated with
securityOrigin
tries to prompt the user for input. The program may provide an optional message,msg
, as well as a default value for the input indefaultValue
.If the prompt was cancelled by the user, the implementation should return
false
; otherwise the result should be written toresult
andtrue
should be returned. If the prompt was not cancelled by the user, the implementation should returntrue
and the result string must not be null.The default implementation uses QInputDialog::getText().
- lifecycleState()¶
- Return type:
See also
Getter of property
lifecycleStateᅟ
.- lifecycleStateChanged(state)¶
- Parameters:
state –
LifecycleState
Notification signal of property
lifecycleStateᅟ
.- linkHovered(url)¶
- Parameters:
url – str
This signal is emitted when the mouse hovers over a link.
url
contains the target URL of the link.Loads
url
into this page.Note
The view remains the same until enough data has arrived to display the new URL.
See also
- load(request)
- Parameters:
request –
QWebEngineHttpRequest
Issues the specified
request
and loads the response.See also
- loadFinished(ok)¶
- Parameters:
ok – bool
This signal is emitted when the page finishes loading content. This signal is independent of script execution or page rendering.
ok
will indicate whether the load was successful or any error occurred.Note
Navigation requests can be delegated to the Qt application instead of having the HTML handler engine process them by overloading the
acceptNavigationRequest()
function. Because the loading process is started and theloadStarted()
signal is emitted before the request is accepted or rejected, aloadFinished()
signal that returnsfalse
is to be expected even after delegating the request.See also
- loadProgress(progress)¶
- Parameters:
progress – int
This signal is emitted when the global progress status changes. The current value is provided by
progress
and scales from 0 to 100, which is the default range of QProgressBar. It accumulates changes from all the child frames.- loadStarted()¶
This signal is emitted when a page starts loading content.
See also
- loadingChanged(loadingInfo)¶
- Parameters:
loadingInfo –
QWebEngineLoadingInfo
This signal is emitted when loading the page specified by
loadingInfo
begins, ends, or fails.Notification signal of property
loadingᅟ
.- mainFrame()¶
- Return type:
The main, top-level frame of the page. All other frames on this page are accessible as children of the main frame.
- Parameters:
request –
QWebEngineNavigationRequest
This signal is emitted on navigation together with the call the
acceptNavigationRequest()
. It can be used to accept or ignore therequest
. The default is to accept.See also
- newWindowRequested(request)¶
- Parameters:
request –
QWebEngineNewWindowRequest
This signal is emitted when
request
is issued to load a page in a separate web engine window. This can either be because the current page requested it explicitly through a JavaScript call towindow.open
, or because the user clicked on a link while holding Shift, Ctrl, or a built-in combination that triggers the page to open in a new window.The signal is handled by calling openIn() with the new page on the request. If this signal is not handled, the requested load will fail.
- pdfPrintingFinished(filePath, success)¶
- Parameters:
filePath – str
success – bool
This signal is emitted when printing the web page into a PDF file has finished.
filePath
will contain the path the file was requested to be created at, andsuccess
will betrue
if the file was successfully created andfalse
otherwise.See also
- permissionRequested(permissionRequest)¶
- Parameters:
permissionRequest –
QWebEnginePermission
This signal is emitted when a web site requests to make use of a feature (e.g. geolocation access, permission to send notifications). The
permission
object can queried for the requesting URL and theQWebEnginePermission::Feature
it’s asking for, as well as to grant or deny permission.- printRequested()¶
This signal is emitted when the JavaScript
window.print()
method is called on the main frame, or the user pressed the print button of PDF viewer plugin. Typically, the signal handler can simply callprintToPdf()
.Since 6.8, this signal is only emitted for the main frame, instead of being emitted for any frame that requests printing.
See also
- printRequestedByFrame(frame)¶
- Parameters:
frame –
QWebEngineFrame
This signal is emitted when the JavaScript
window.print()
method is called onframe
. If the frame is the main frame,printRequested
is emitted instead.See also
- printToPdf(resultCallback[, pageLayout=QPageLayout(QPageSize(QPageSize.A4), QPageLayout.Portrait, QMarginsF())[, ranges={}]])¶
- Parameters:
resultCallback –
PyCallable
pageLayout –
QPageLayout
ranges –
QPageRanges
Renders the current content of the page into a PDF document and returns a byte array containing the PDF data as parameter to
resultCallback
.The page size and orientation of the produced PDF document are taken from the values specified in
layout
, while the range of pages printed is taken fromranges
with the default being printing all pages.Note
The
QWebEnginePage.WebAction.Stop
web action can be used to interrupt this operation.Note
We guarantee that the
resultCallback
is always called, but it might be done during page destruction. WhenQWebEnginePage
is deleted, the callback is triggered with an invalid value and it is not safe to use the correspondingQWebEnginePage
,QWebEngineFrame
, orQWebEngineView
instance inside it.- printToPdf(filePath[, layout=QPageLayout(QPageSize(QPageSize.A4), QPageLayout.Portrait, QMarginsF())[, ranges={}]])
- Parameters:
filePath – str
layout –
QPageLayout
ranges –
QPageRanges
Renders the current content of the page into a PDF document and saves it in the location specified in
filePath
. The page size and orientation of the produced PDF document are taken from the values specified inlayout
, while the range of pages printed is taken fromranges
with the default being printing all pages.This method issues an asynchronous request for printing the web page into a PDF and returns immediately. To be informed about the result of the request, connect to the signal
pdfPrintingFinished()
.Note
The
Stop
web action can be used to interrupt this asynchronous operation.If a file already exists at the provided file path, it will be overwritten.
See also
- profile()¶
- Return type:
Returns the web engine profile the page belongs to.
- proxyAuthenticationRequired(requestUrl, authenticator, proxyHost)¶
- Parameters:
requestUrl –
QUrl
authenticator –
QAuthenticator
proxyHost – str
This signal is emitted when access to
requestUrl
viaproxyHost
requires authentication for the proxy.authenticator
should be used to pass the user name and password for the connection.- quotaRequested(quotaRequest)¶
- Parameters:
quotaRequest –
QWebEngineQuotaRequest
Note
This function is deprecated.
This signal is no longer emitted.
Requesting host quota is no longer supported by Chromium. The behavior of navigator.webkitPersistentStorage is identical to navigator.webkitTemporaryStorage.
For further details, see https://crbug.com/1233525
- recentlyAudible()¶
- Return type:
bool
Getter of property
recentlyAudibleᅟ
.- recentlyAudibleChanged(recentlyAudible)¶
- Parameters:
recentlyAudible – bool
This signal is emitted when the page’s audible state,
recentlyAudible
, changes, because the audio is played or stopped.Note
The signal is also emitted when calling the
setAudioMuted()
method.Notification signal of property
recentlyAudibleᅟ
.- recommendedState()¶
- Return type:
Getter of property
recommendedStateᅟ
.- recommendedStateChanged(state)¶
- Parameters:
state –
LifecycleState
Notification signal of property
recommendedStateᅟ
.- registerProtocolHandlerRequested(request)¶
- Parameters:
request –
QWebEngineRegisterProtocolHandlerRequest
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This signal is emitted when the web page tries to register a custom protocol using the registerProtocolHandler API.
The request object
request
can be used to accept or reject the request:def handleRegisterProtocolHandlerRequested(self): QWebEngineRegisterProtocolHandlerRequest request) answer = QMessageBox.question(window(), tr("Permission Request"),() tr("Allow %1 to open all %2 links?") .arg(request.origin().host()) .arg(request.scheme())) if answer == QMessageBox.Yes: request.accept() else: request.reject()
- renderProcessPid()¶
- Return type:
int
Getter of property
renderProcessPidᅟ
.- renderProcessPidChanged(pid)¶
- Parameters:
pid – int
This signal is emitted when the underlying render process PID,
pid
, changes.Notification signal of property
renderProcessPidᅟ
.- renderProcessTerminated(terminationStatus, exitCode)¶
- Parameters:
terminationStatus –
RenderProcessTerminationStatus
exitCode – int
This signal is emitted when the render process is terminated with a non-zero exit status.
terminationStatus
is the termination status of the process andexitCode
is the status code with which the process terminated.- replaceMisspelledWord(replacement)¶
- Parameters:
replacement – str
Replace the current misspelled word with
replacement
.The current misspelled word can be found in
misspelledWord()
, and suggested replacements inspellCheckerSuggestions()
.Getter of property
requestedUrlᅟ
.- runJavaScript(scriptSource, resultCallback)¶
- Parameters:
scriptSource – str
resultCallback –
PyCallable
- runJavaScript(scriptSource[, worldId=0[, resultCallback={}]])
- Parameters:
scriptSource – str
worldId – int
resultCallback –
PyCallable
Runs the JavaScript code contained in
scriptSource
script on this frame, without checking whether the DOM of the page has been constructed.To avoid conflicts with other scripts executed on the page, the world in which the script is run is specified by
worldId
. The world ID values are the same as provided byQWebEngineScript.ScriptWorldId
, and between 0 and 256. If you leave out the world ID, the script is run in theMainWorld
(0).When the script has been executed, the callable
resultCallback
is called with the result of the last executed statement.Only plain data can be returned from JavaScript as the result value.
Note
Do not execute lengthy routines in the callback function, because it might block the rendering of the web engine page.
Note
We guarantee that the
resultCallback
is always called, but it might be done during page destruction. WhenQWebEnginePage
is deleted, the callback is triggered with an invalid value and it is not safe to use the correspondingQWebEnginePage
,QWebEngineFrame
, orQWebEngineView
instance inside it.- save(filePath[, format=QWebEngineDownloadRequest.MimeHtmlSaveFormat])¶
- Parameters:
filePath – str
format –
SavePageFormat
Save the currently loaded web page to disk.
The web page is saved to
filePath
in the specifiedformat
.This is a short cut for the following actions:
Trigger the Save web action.
Accept the next download item and set the specified file path and save format.
This function issues an asynchronous download request for the web page and returns immediately.
See also
- scripts()¶
- Return type:
Returns the collection of scripts that are injected into the page.
In addition, a page might also execute scripts added through
scripts()
.Getter of property
scrollPositionᅟ
.Notification signal of property
scrollPositionᅟ
.- selectClientCertificate(clientCertSelection)¶
- Parameters:
clientCertSelection –
QWebEngineClientCertificateSelection
This signal is emitted when a web site requests an SSL client certificate, and one or more were found in system’s client certificate store.
Handling the signal is asynchronous, and loading will be waiting until a certificate is selected, or the last copy of
clientCertificateSelection
is destroyed.If the signal is not handled,
clientCertificateSelection
is automatically destroyed, and loading will continue without a client certificate.See also
- selectedText()¶
- Return type:
str
Getter of property
selectedTextᅟ
.- selectionChanged()¶
This signal is emitted whenever the selection changes, either interactively or programmatically. For example, by calling
triggerAction()
with a selection action.Note
When using the mouse to select text by left-clicking and dragging, the signal will be emitted for each new character selected, and not upon releasing the left mouse button.
See also
- setAudioMuted(muted)¶
- Parameters:
muted – bool
See also
Setter of property
audioMutedᅟ
.Setter of property
backgroundColorᅟ
.- setContent(data[, mimeType=""[, baseUrl=QUrl()]])¶
- Parameters:
data –
QByteArray
mimeType – str
baseUrl –
QUrl
Sets the content of the web page to
data
. If themimeType
argument is empty, it is assumed that the content istext/plain,charset=US-ASCII
.External objects referenced in the content are located relative to
baseUrl
. For external objects with relative URLs to be loaded,baseUrl
cannot be empty.The
data
is loaded immediately; external objects are loaded asynchronously.Note
This method will not affect session or global history for the page.
Warning
The content will be percent encoded before being sent to the renderer via IPC. This may increase its size. The maximum size of the percent encoded content is 2 megabytes minus 6 bytes plus the length of the mime type string.
- setDevToolsPage(page)¶
- Parameters:
page –
QWebEnginePage
Binds
devToolsPage
to be the developer tools of this page. TriggersdevToolsPage
to navigate to an internal URL with the developer tools.This is the same as calling
setInspectedPage()
ondevToolsPage
withthis
as argument.See also
- setFeaturePermission(securityOrigin, feature, policy)¶
- Parameters:
securityOrigin –
QUrl
feature –
Feature
policy –
PermissionPolicy
Note
This function is deprecated.
Use
QWebEnginePermission
‘sgrant
(),deny
(), andreset
() functions instead.Sets the permission for the web site identified by
securityOrigin
to usefeature
topolicy
.Note
This method is primarily for calling after a
featurePermissionRequested()
signal has been emitted to trigger the feature permission response. It can also be called before a request has been emitted, but will only set a granted permission for passive checks, mainly for Notification APIs that can check if permission has already been granted before explicitly requesting it.Sets the content of this page to
html
.baseUrl
is optional and used to resolve relative URLs in the document, such as referenced images or stylesheets.The
html
is loaded immediately; external objects are loaded asynchronously.If a script in the
html
runs longer than the default script timeout (currently 10 seconds), for example due to being blocked by a modal JavaScript alert dialog, this method will return as soon as possible after the timeout and any subsequenthtml
will be loaded asynchronously.When using this method, the web engine assumes that external resources, such as JavaScript programs or style sheets, are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external script can be specified through the charset attribute of the HTML script tag. It is also possible for the encoding to be specified by the web server.
This is a convenience function equivalent to
setContent
(html, “text/html”, baseUrl).Note
This method will not affect session or global history for the page.
Warning
This function works only for HTML, for other mime types (such as XHTML and SVG)
setContent()
should be used instead.Warning
The content will be percent encoded before being sent to the renderer via IPC. This may increase its size. The maximum size of the percent encoded content is 2 megabytes minus 30 bytes.
See also
- setInspectedPage(page)¶
- Parameters:
page –
QWebEnginePage
Navigates this page to an internal URL that is the developer tools of
page
.This is the same as calling
setDevToolsPage()
onpage
withthis
as argument.See also
- setLifecycleState(state)¶
- Parameters:
state –
LifecycleState
See also
Setter of property
lifecycleStateᅟ
.Setter of property
urlᅟ
.- setUrlRequestInterceptor(interceptor)¶
- Parameters:
interceptor –
QWebEngineUrlRequestInterceptor
Registers the request interceptor
interceptor
to intercept URL requests.The page does not take ownership of the pointer. This interceptor is called after any interceptors on the profile, and unlike profile interceptors, only URL requests from this page are intercepted. If the original request was already blocked or redirected by the profile interceptor, it will not be intercepted by this.
To unset the request interceptor, set a
nullptr
.- setVisible(visible)¶
- Parameters:
visible – bool
See also
Setter of property
visibleᅟ
.- setWebChannel(arg__1[, worldId=0])¶
- Parameters:
arg__1 –
QWebChannel
worldId – int
Sets the web channel instance to be used by this page to
channel
and connects it to web engine’s transport using Chromium IPC messages. The transport is exposed in the JavaScript worldworldId
asqt.webChannelTransport
, which should be used when using the Qt WebChannel JavaScript API.Note
The page does not take ownership of the channel object.
Note
Only one web channel can be installed per page, setting one even in another JavaScript world uninstalls any already installed web channel.
See also
- setZoomFactor(factor)¶
- Parameters:
factor – float
See also
Setter of property
zoomFactorᅟ
.- settings()¶
- Return type:
Returns a pointer to the page’s settings object.
- title()¶
- Return type:
str
Getter of property
titleᅟ
.- titleChanged(title)¶
- Parameters:
title – str
This signal is emitted whenever the title of the page changes. The
title
string specifies the new title.See also
Notification signal of property
titleᅟ
.- toHtml(resultCallback)¶
- Parameters:
resultCallback –
PyCallable
Asynchronous method to retrieve the page’s content as HTML, enclosed in HTML and BODY tags. Upon successful completion,
resultCallback
is called with the page’s content.Note
We guarantee that the
resultCallback
is always called, but it might be done during page destruction. WhenQWebEnginePage
is deleted, the callback is triggered with an invalid value and it is not safe to use the correspondingQWebEnginePage
,QWebEngineFrame
, orQWebEngineView
instance inside it.- toPlainText(resultCallback)¶
- Parameters:
resultCallback –
PyCallable
Asynchronous method to retrieve the page’s content converted to plain text, completely stripped of all HTML formatting.
Upon successful completion,
resultCallback
is called with the page’s content.Note
We guarantee that the
resultCallback
is always called, but it might be done during page destruction. WhenQWebEnginePage
is deleted, the callback is triggered with an invalid value and it is not safe to use the correspondingQWebEnginePage
,QWebEngineFrame
, orQWebEngineView
instance inside it.This function can be called to trigger the specified
action
. It is also called by Qt WebEngine if the user triggers the action, for example through a context menu item.If
action
is a checkable action, thenchecked
specifies whether the action is toggled or not.See also
Getter of property
urlᅟ
.This signal is emitted with the URL of the page when the page title is received. The new URL is specified by
url
.See also
Notification signal of property
urlᅟ
.- visibleChanged(visible)¶
- Parameters:
visible – bool
Notification signal of property
visibleᅟ
.- webAuthUxRequested(request)¶
- Parameters:
request –
QWebEngineWebAuthUxRequest
This signal is emitted when a WebAuth authenticator needs user interaction during the authentication process. These requests are handled by displaying a dialog to the user.
The
request
contains the information and API required to complete the WebAuth UX request.See also
- webChannel()¶
- Return type:
Returns a pointer to the web channel instance used by this page or a null pointer if none was set. This channel automatically uses the internal web engine transport mechanism over Chromium IPC that is exposed in the JavaScript context of this page as
qt.webChannelTransport
.See also
- windowCloseRequested()¶
This signal is emitted whenever the page requests the web browser window to be closed, for example through the JavaScript
window.close()
call.See also
- zoomFactor()¶
- Return type:
float
See also
Getter of property
zoomFactorᅟ
.- zoomFactorChanged(factor)¶
- Parameters:
factor – float
This signal is emitted whenever the zoom
factor
for the page changes.See also
Notification signal of property
zoomFactorᅟ
.