FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cefpython/examples/snippets/javascript_errors.py at cefpython66 · 2php/cefpython · GitHub
2php
cefpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cefpython
/
examples
/
snippets
/
javascript_errors.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (53 loc) · 1.54 KB
Breadcrumbs
cefpython
/
examples
/
snippets
/
javascript_errors.py
Copy path
File metadata and controls
61 lines (53 loc) · 1.54 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
51
52
53
54
55
56
57
58
59
60
61
"""
Two ways for intercepting Javascript errors:
1. window.onerror event in Javascript
2. DisplayHandler.OnConsoleMessage in Python
"""
from
cefpython3
import
cefpython
as
cef
g_htmlcode
=
"""
<!doctype html>
<html>
<head>
<style>
body, html {
font-family: Arial;
font-size: 11pt;
}
</style>
<script>
function print(msg) {
document.getElementById("console").innerHTML += msg+"<br>";
}
window.onerror = function(message, source, lineno, colno, error) {
print("[JS:window.onerror] "+error+" (line "+lineno+")");
// Return false so that default event handler is fired and
// OnConsoleMessage can also intercept this error.
return false;
};
window.onload = function() {
forceError();
};
</script>
</head>
<body>
<h1>Javascript Errors</h1>
<div id=console></div>
</body>
</html>
"""
def
main
():
cef
.
Initialize
()
browser
=
cef
.
CreateBrowserSync
(
url
=
cef
.
GetDataUrl
(
g_htmlcode
),
window_title
=
"Javascript Errors"
)
browser
.
SetClientHandler
(
DisplayHandler
())
cef
.
MessageLoop
()
cef
.
Shutdown
()
class
DisplayHandler
(
object
):
def
OnConsoleMessage
(
self
,
browser
,
message
,
line
,
**
_
):
if
"error"
in
message
.
lower
()
or
"uncaught"
in
message
.
lower
():
logmsg
=
"[Py:OnConsoleMessage] {message} (line {line})"
\
.
format
(
message
=
message
,
line
=
line
)
print
(
logmsg
)
browser
.
ExecuteFunction
(
"print"
,
logmsg
)
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL