Frame (object)

January 20, 2020 ยท View on GitHub

API categories | API index

Frame (object)

Remember to free all frame references for the browser to shut down cleanly. Otherwise data such as cookies or other storage might not be flushed to disk when closing app, and other issues might occur as well. If you store a reference to Frame somewhere in your code then to free it just assign a None value to the variable.

To compare frame objects always use GetIdentifier() method. Do not compare two Frame objects variables directly. There are some edge cases when after the OnBeforeClose event frame objects are no more globally referenced thus a new instance is created that wraps upstream CefFrame object. Frame objects that were globally unreferenced do not have properties of the original Frame object.

Table of contents:

Methods

Copy

Returnvoid

Execute copy in this frame.

Cut

Returnvoid

Execute cut in this frame.

Delete

Returnvoid

Execute delete in this frame.

ExecuteFunction

ParameterType
funcNamestring
..*args
Returnvoid

Call a javascript function asynchronously. This can also call object's methods, just pass "object.method" as funcName. Any valid javascript syntax is allowed as funcName, you could even pass an anonymous function here. For a list of allowed types of arguments see JavascriptBindings.IsValueAllowed() - except function, method and instance. Passing a python function here is not allowed, it is only possible using the JavascriptCallback object.

ExecuteJavascript

ParameterType
jsCodestring
scriptUrl=""string
startLine=1int
Returnvoid

Execute a string of JavaScript code in this frame. The sciptUrl parameter is the url where the script in question can be found, if any. The renderer may request this URL to show the developer the source of the error. The startLine parameter is the base line number to use for error reporting. This function executes asynchronously so there is no way to get the returned value. Calling javascript <> native code synchronously is not possible.

GetBrowser

ReturnBrowser

Returns the browser that this frame belongs to.

GetParent

ReturnFrame

Returns the parent of this frame or None if this is the main (top-level) frame.

GetIdentifier

Returnint

Frame identifiers are unique per render process, they are not globally unique.

Returns < 0 if the underlying frame does not yet exist.

GetBrowserIdentifier

Returnint

Returns the globally unique identifier for the browser hosting this frame.

GetName

Returnstring

Returns the name for this frame. If the frame has an assigned name (for example, set via the iframe "name" attribute) then that value will be returned. Otherwise a unique name will be constructed based on the frame parent hierarchy. The main (top-level) frame will always have an empty name value.

GetParent

ReturnFrame

Returns the parent of this frame or None if this is the main (top-level) frame. This method should only be called on the UI thread.

GetSource

ParameterType
visitorStringVisitor
Returnvoid

Retrieve this frame's HTML source as a string sent to the specified visitor.

GetText

ParameterType
visitorStringVisitor
Returnvoid

Retrieve this frame's display text as a string sent to the specified visitor.

GetUrl

Returnstring

Returns the url currently loaded in this frame.

IsFocused

Returnbool

Returns true if this is the focused frame. This method should only be called on the UI thread.

IsMain

Returnbool

Returns true if this is the main (top-level) frame.

IsValid

Returnbool

True if this object is currently attached to a valid frame.

LoadString

ParameterType
valuestring
urlstring
Returnvoid

NOTE: LoadString is problematic due to the multi-process model and the need to create a render process (which does not happen with LoadString). It is best to use instead LoadUrl with a data uri, e.g. LoadUrl("data:text/html,some+html+code+here"). Take also a look at a custom resource handler.

Load the contents of |value| with the specified dummy |url|. |url| should have a standard scheme (for example, http scheme) or behaviors like link clicks and web security restrictions may not behave as expected. LoadString() can be called only after the Renderer process has been created.

If the url is a local path it needs to start with the file:// prefix. If the url contains special characters it may need proper handling. Starting with v66.1+ it is required for the app code to encode the url properly. You can use the pathlib.PurePath.as_uri in Python 3 or urllib.pathname2url in Python 2 (urllib.request.pathname2url in Python 3) depending on your case.

LoadUrl

ParameterType
urlstring
Returnvoid

Load the specified |url|.

Paste

Returnvoid

Execute paste in this frame.

Redo

Returnvoid

Execute redo in this frame.

SelectAll

Returnvoid

Execute select all in this frame.

Undo

Returnvoid

Execute undo in this frame.

ViewSource

Returnvoid

Save this frame's HTML source to a temporary file and open it in the default text viewing application.