MCPcopy Create free account
hub / github.com/cztomczak/cefpython / save_screenshot

Function save_screenshot

examples/screenshot.py:150–162  ·  view source on GitHub ↗
(browser)

Source from the content-addressed store, hash-verified

148
149
150def save_screenshot(browser):
151 # Browser object provides GetUserData/SetUserData methods
152 # for storing custom data associated with browser. The
153 # "OnPaint.buffer_string" data is set in RenderHandler.OnPaint.
154 buffer_string = browser.GetUserData("OnPaint.buffer_string")
155 if not buffer_string:
156 raise Exception("buffer_string is empty, OnPaint never called?")
157 image = Image.frombytes("RGBA", VIEWPORT_SIZE, buffer_string,
158 "raw", "RGBA", 0, 1)
159 image.save(SCREENSHOT_PATH, "PNG")
160 print("[screenshot.py] Saved image: {path}".format(path=SCREENSHOT_PATH))
161 # See comments in exit_app() why PostTask must be used
162 cef.PostTask(cef.TID_UI, exit_app, browser)
163
164
165def open_with_default_application(path):

Callers

nothing calls this directly

Calls 1

PostTaskMethod · 0.80

Tested by

no test coverage detected