FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cefpython/examples/snippets/ondomready.py at cefpython49-winxp · pythonthings/cefpython · GitHub
pythonthings
cefpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cefpython
/
examples
/
snippets
/
ondomready.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (40 loc) · 1.42 KB
Breadcrumbs
cefpython
/
examples
/
snippets
/
ondomready.py
Copy path
File metadata and controls
50 lines (40 loc) · 1.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Execute custom Python code on a web page as soon as DOM is ready.
Implements a custom "_OnDomReady" event in the LoadHandler object.
"""
from
cefpython3
import
cefpython
as
cef
def
main
():
cef
.
Initialize
()
browser
=
cef
.
CreateBrowserSync
(
url
=
"https://www.google.com/"
,
window_title
=
"_OnDomReady event"
)
load_handler
=
LoadHandler
(
browser
)
browser
.
SetClientHandler
(
load_handler
)
bindings
=
cef
.
JavascriptBindings
()
bindings
.
SetFunction
(
"LoadHandler_OnDomReady"
,
load_handler
[
"_OnDomReady"
])
browser
.
SetJavascriptBindings
(
bindings
)
cef
.
MessageLoop
()
del
load_handler
del
browser
cef
.
Shutdown
()
class
LoadHandler
(
object
):
def
__init__
(
self
,
browser
):
self
.
browser
=
browser
def
__getitem__
(
self
,
key
):
return
getattr
(
self
,
key
)
def
OnLoadStart
(
self
,
browser
,
**
_
):
browser
.
ExecuteJavascript
(
"""
if (document.readyState === "complete") {
LoadHandler_OnDomReady();
} else {
document.addEventListener("DOMContentLoaded", function() {
LoadHandler_OnDomReady();
});
}
"""
)
def
_OnDomReady
(
self
):
print
(
"DOM is ready!"
)
self
.
browser
.
ExecuteFunction
(
"alert"
,
"Message from Python: DOM is ready!"
)
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL