-
Notifications
You must be signed in to change notification settings - Fork 0
cefpython
This function was not yet ported to CEF Python.
Create browser asynchronously. The actual window will be created on the UI thread. This method call will not block.
CreateBrowserSync(WindowInfo windowInfo, dict browserSettings, string navigateUrl, void requestContext) (Browser)
This function should only be called on the UI thread.
The
requestContextparameter is not yet implemented.
You must first create a window and initialize
windowInfoby calling WindowInfo.SetAsChild.
After the call to CreateBrowserSync() the page is not yet loaded, if you want your next lines of code to do some stuff on the webpage you will have to implement LoadHandler.OnLoadEnd() callback, see example below:
def OnLoadEnd(browser, frame, httpCode):
if frame == browser.GetMainFrame():
print "Finished loading main frame: %s (http code = %d)" % (frame.GetUrl(), httpCode)
browser = cefpython.CreateBrowserSync(windowInfo, settings, url)
browser.SetClientCallback("OnLoadEnd", OnLoadEnd)
Returns stack trace as a nicely formatted string. Call GetJavascriptStackTrace() to get stack trace as a list.
Returns ApplicationSettings option that was passed to
Initialize(). Returns None if key is not found.
Get browser by outer or inner window handle. An outer window handle is the one that was passed to
CreateBrowserSync(). An inner window handle is a CEF internal window handle.
Returns the CommandLineSwitches switch that was passed to
Initialize(). Returns None if key is not found.
Returns a global client callback that was set using
SetGlobalClientCallback(). Returns None if callback was not set.
Returns the stack trace for the currently active context. |frameLimit| is the maximum number of frames that will be captured. This function may be called only on the UI thread.
Frames in the returned list are of type dictionary with following keys:
- script
- scriptOrSourceUrl (the name of the script or the sourceUrl value if the script name is undefined and its source ends with "//@ sourceURL=...".)
- function
- line
- column
- isEval (whether function was compiled using eval())
- isConstructor (whether function was called as a constructor via "new")
Get the cefpython module directory. This method is useful to get full path to CEF binaries. This is required when setting options like ApplicationSettings.browser_subprocess_path / resources_dir_path / locales_dir_path.
Initialize(dict applicationSettings=None, dict commandLineSwitches=None) (bool)
This function should be called on the main application thread (UI thread) to initialize CEF when the application is started.
A call toInitialize()must have a corresponding call toShutdown(), otherwise when application closes, the process might freeze (experienced on Windows XP).
The commandLineSwitches param is a dictionary with switch name as key. The switch name should not containt the "-" or "--" prefix. Switch value may be an empty string, if switch doesn't require a value. These switches are set for the main process and all subprocesses. With switches you can set various options in Chromium. For example a proxy can be set with the "proxy-server" switch. The default of using IE proxy settings can be disabld with the "no-proxy-server" switch. To enable Enable media (webrtc/audio) streaming set the "enable-media-stream" switch. See the CommandLineSwitches wiki page for a list of all available switches that can be set.
When debbugging is On, the whole command line string will be displayed in console, with both CEF switches set internally, and the ones appended by cefpython. On Linux you will also see in console the command line string for subprocesses. On Windows, command line strings for subprocesses won't be seen in console, you can view them by opening the debug.log file. Example command line strings from debug logs, for the main process and the renderer process:
# Main process
python --browser-subprocess-path="C:\cefpython\cefpython\cef3\windows\binaries/subprocess"
--lang=en-US --log-file="C:\cefpython\cefpython\cef3\windows\binaries\debug.log"
--log-severity=info --enable-release-dcheck --no-sandbox wxpython.py
# Renderer process
"C:\cefpython\cefpython\cef3\windows\binaries/subprocess" --type=renderer --no-sandbox
--lang=en-US --lang=en-US --log-file="C:\cefpython\cefpython\cef3\windows\binaries\debug.log"
--log-severity=info --enable-release-dcheck --channel="4152.0.209609692\1183564454"
/prefetch:673131151
Returns true if called on the specified thread.
CEF maintains multiple internal threads that are used for handling different types of tasks. The UI thread creates the browser window and is used for all interaction with the webkit rendering engine and V8 Javascript engine (The UI thread will be the same as the main application thread if CefInitialize() is called with a ApplicationSettings.multi_threaded_message_loop value of false.) The IO thread is used for handling schema and network requests. The FILE thread is used for the application cache and other miscellaneous activities.
List of threads in the Browser process. These are constants defined in the cefpython module:
- TID_UI: The main thread in the browser. This will be the same as the main application thread if cefpython.Initialize() is called with a ApplicationSettings.multi_threaded_message_loop value of false.
- TID_DB: Used to interact with the database.
- TID_FILE: Used to interact with the file system.
- TID_FILE_USER_BLOCKING: Used for file system operations that block user interactions. Responsiveness of this thread affects users.
- TID_PROCESS_LAUNCHER: Used to launch and terminate browser processes.
- TID_CACHE: Used to handle slow HTTP cache operations.
- TID_IO: Used to process IPC and network messages.
List of threads in the Renderer process:
- TID_RENDERER: The main thread in the renderer. Used for all webkit and V8 interaction.
For use with KeyboardHandler to check whether ALT, SHIFT or CTRL are pressed.
Run the CEF message loop. Use this function instead of an application-
provided message loop to get the best balance between performance and CPU usage. This function should only be called on the main application thread (UI thread) and only if cefpython.Initialize() is called with a
ApplicationSettings.multi_threaded_message_loop value of false. This function will block until a quit message is received by the system.
Perform a single iteration of CEF message loop processing. This function is used to integrate the CEF message loop into an existing application message loop. Care must be taken to balance performance against excessive CPU usage. This function should only be called on the main application thread (UI thread) and only if cefpython.Initialize() is called with a ApplicationSettings.multi_threaded_message_loop value of false. This function will not block.
Alternatively you could create a periodic timer (with 10 ms interval) that calls cefpython.MessageLoopWork().
CefDoMessageLoopWork is not tested on OS X and there are known issues - according to this comment by Marshall.
Post a task for execution on the thread associated with this task runner. Execution will occur asynchronously. Only Browser process threads are allowed, see IsThread() for a list of available threads and their descriptions.
An example usage is in the wxpython.py example on Windows, in implementation of LifespanHandler.OnBeforePopup.
Quit the CEF message loop that was started by calling cefpython.MessageLoop(). This function should only be called on the main application thread (UI thread) and only if cefpython.MessageLoop() was used.
Current CEF Python implementation is limited in handling callbacks that occur during browser creation, in such cases a callback set with Browser.SetClientCallback()or Browser.SetClientHandler()won't work, as this methods can be called only after browser was created. An example of such callback is LifespanHandler.OnAfterCreated.
Some client callbacks are not associated with any browser. In such case use this function
instead of the Browser.SetClientCallback()/SetClientHandler()methods. An example of such callback is RequestHandler.OnCertificateError.
Example of using SetGlobalClientCallback is provided in the wxpython.py example.
Set to true before calling Windows APIs likeTrackPopupMenuthat enter a
modal message loop. Set to false after exiting the modal message loop.
This function should be called on the main application thread (UI thread) to shut down CEF before the application exits.
You must call this function so that CEF shuts down cleanly. Remember also to delete all CEF browsers references for the browsers to shut down cleanly. For an example see wxpython.py > MainFrame.OnClose().