Skip to content

Commit ccc03c8

Browse files
committed
Add onbeforeclose.py snippet
1 parent 56f7419 commit ccc03c8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/snippets/onbeforeclose.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Implement LifespanHandler.OnBeforeClose to execute custom
2+
# code before browser window closes.
3+
4+
from cefpython3 import cefpython as cef
5+
6+
7+
def main():
8+
cef.Initialize()
9+
browser = cef.CreateBrowserSync(url="https://www.google.com/",
10+
window_title="OnBeforeClose")
11+
browser.SetClientHandler(LifespanHandler())
12+
cef.MessageLoop()
13+
del browser
14+
cef.Shutdown()
15+
16+
17+
class LifespanHandler(object):
18+
def OnBeforeClose(self, browser):
19+
print("Browser ID: {}".format(browser.GetIdentifier()))
20+
print("Browser will close and app will exit")
21+
22+
23+
if __name__ == '__main__':
24+
main()

0 commit comments

Comments
 (0)