forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcefadvanced.html
More file actions
306 lines (236 loc) · 14.4 KB
/
cefadvanced.html
File metadata and controls
306 lines (236 loc) · 14.4 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>CefAdvanced</title>
<style>
body { font: 13px Segoe UI, Arial; line-height: 1.4em; }
pre { background: #ddd; font: 12px Consolas, Courier New; }
h4 { color: #666; margin: 1em 0em; }
</style>
</head>
<body>
Welcome to <b>CEF Python</b> - bindings for the Chromium Embedded Framework.
<br><br>
Project website: <a href="http://code.google.com/p/cefpython/">
http://code.google.com/p/cefpython/</a><br>
Wiki documentation: <a href="http://code.google.com/p/cefpython/wiki/">
http://code.google.com/p/cefpython/wiki/</a><br>
Support forum: <a href="https://groups.google.com/group/cefpython?hl=en">
https://groups.google.com/group/cefpython?hl=en</a><br>
<h3>User agent</h3>
<script>document.write(navigator.userAgent)</script>
<h3>Python version</h3>
<script>document.write(python.Version())</script>
<h3>Keyboard and mouse shortcuts</h3>
<ul>
<li>Press F5 to refresh & rebind python<>javascript bindings
(does not work for the main module).
<li>Press F11 to go fullscreen, press F11 again to exit fullscreen.
<li>Press F12 key to show developer tools for the main frame.
<li>Press backspace to go Back in history.
<li>Use right mouse button context menu to go Back/Forward or to view the sources.
<li>Press Ctrl(+) to zoom in, Ctrl(-) to zoom out.
</ul>
<h3>Browse google</h3>
<a href="http://www.google.com/">http://www.google.com/</a>
<h3>Transparent window</h3>
<a href="javascript:python.TransparentPopup()">
python.TransparentPopup()</a>
<h3>Browser object</h3>
<a href="javascript:alert(browser.CanGoBack())">CanGoBack()</a><br>
<a href="javascript:alert(browser.CanGoForward())">CanGoForward()</a><br>
<a href="javascript:browser.ClearHistory()">ClearHistory()</a><br>
<a href="javascript:browser.CloseBrowser()">CloseBrowser()</a><br>
<a href="javascript:browser.CloseDevTools()">CloseDevTools()</a><br>
<a href="javascript:browser.Find(searchID=0, searchText='test', forward=true, matchCase=false, findNext=false)">Find(searchId=0, searchText='test', forward=true, matchCase=false, findNext=false)</a><br>
<a href="javascript:alert(browser.GetUserData('some'))">GetUserData('some')</a><br>
<a href="javascript:alert(browser.GetFocusedFrame())">GetFocusedFrame()</a>
- throws an error, returning a PyFrame object to to javascript is not yet supported<br>
<a href="javascript:alert(browser.GetFrame('simple'))">GetFrame('simple')</a> - throws an error, returning a PyFrame object to javascript is not yet supported<br>
<a href="javascript:alert(browser.GetFrameNames())">GetFrameNames()</a><br>
<a href="javascript:alert(browser.GetMainFrame())">GetMainFrame()</a>
- throws an error, returning a PyFrame object to javascript is not yet supported<br>
<a href="javascript:alert(browser.GetOpenerWindowHandle())">
GetOpenerWindowHandle()</a><br>
<a href="javascript:alert(browser.GetOuterWindowHandle())">
GetOuterWindowHandle()</a><br>
<a href="javascript:alert(browser.GetWindowHandle())">GetWindowHandle()</a><br>
<a href="javascript:alert(browser.GetZoomLevel())">GetZoomLevel()</a><br>
<a href="javascript:browser.GoBack()">GoBack()</a><br>
<a href="javascript:browser.GoForward()">GoForward()</a><br>
<a href="javascript:alert(browser.HasDocument())">HasDocument()</a><br>
<a href="javascript:browser.HidePopup()">HidePopup()</a><br>
<a href="javascript:alert(browser.IsFullscreen())">IsFullscreen()</a><br>
<a href="javascript:alert(browser.IsPopup())">IsPopup()</a><br>
<a href="javascript:alert(browser.IsPopupVisible())">IsPopupVisible()</a><br>
<a href="javascript:alert(browser.IsWindowRenderingDisabled())">
IsWindowRenderingDisabled()</a><br>
<a href="javascript:browser.Reload()">Reload()</a><br>
<a href="javascript:browser.ReloadIgnoreCache()">ReloadIgnoreCache()</a><br>
<a href="javascript:browser.SetFocus(false)">SetFocus(false)</a>
- inner window loses focus, check keyboard and mouse wheel scrolling<br>
<a href="javascript:browser.SetUserData('some', 'something')">
SetUserData('some', 'something')</a> - call GetUserData('some')<br>
<a href="javascript:browser.SetZoomLevel(2)">SetZoomLevel(2)</a><br>
<a href="javascript:browser.ShowDevTools()">ShowDevTools()</a><br>
<a href="javascript:browser.StopLoad()">StopLoad()</a><br>
<a href="javascript:browser.StopFinding(true)">StopFinding(true)</a> - call Find(), then StopFinding()<br>
<a href="javascript:browser.ToggleFullscreen()">ToggleFullscreen()</a><br>
<h3>Frame object</h3>
<a href="javascript:(frame.Copy())">Copy()</a><br>
<a href="javascript:(frame.Cut())">Cut()</a><br>
<a href="javascript:(frame.Delete())">Delete()</a><br>
<a href="javascript:((frame.ExecuteJavascript('alert(1)')))">
ExecuteJavascript('alert(1)')</a><br>
<a href="javascript:(alert(frame.GetIdentifier()))">GetIdentifier()</a><br>
<script>window.name="This string was set using 'window.name'";</script>
<a href="javascript:(alert(frame.GetName()))">GetName()</a><br>
<a href="javascript:(alert(frame.GetProperty('name')))">GetProperty('name')</a><br>
<a href="javascript:(alert(frame.GetSource()))">GetSource()</a><br>
<a href="javascript:(alert(frame.GetText()))">GetText()</a><br>
<a href="javascript:(alert(frame.GetUrl()))">GetUrl()</a><br>
<a href="javascript:(alert(frame.IsFocused()))">IsFocused()</a><br>
<a href="javascript:(alert(frame.IsMain()))">IsMain()</a><br>
<a href="javascript:((frame.LoadString('some html source', 'cef://some')))">LoadString('some html source', 'cef://some')</a><br>
<a href="javascript:((frame.LoadUrl('http://www.google.com/')))">
LoadUrl('http://www.google.com/')</a><br>
<a href="javascript:((frame.Paste()))">Paste()</a><br>
<a href="javascript:((frame.Print()))">Print()</a><br>
<a href="javascript:((frame.Redo()))">Redo()</a><br>
<a href="javascript:((frame.SelectAll()))">SelectAll()</a><br>
<a href="javascript:((frame.SetProperty('name', 'noname')))">
SetProperty('name', 'noname')</a> - call GetProperty('name')<br>
<a href="javascript:((frame.Undo()))">Undo()</a><br>
<a href="javascript:((frame.ViewSource()))">ViewSource()</a><br>
<h3>Browser view as an image</h3>
Browser.GetImage() returns a PaintBuffer object that has the GetString()
method that returns the buffer as a string, that string can be
passed to PIL.Image.fromstring() and saved as a PNG or other
format. This test requires the PIL or pygame library to be installed:<br>
<a href="javascript:python.SaveImage('!cefadvanced.png', 'PNG')">
python.SaveImage('!cefadvanced.png', 'PNG')</a><br>
TODO: capture image of all the scrollable content on a webpage,
detect the height of the content in javascript and call
Browser.SetSize() using that height.
<h3>Test unicode string</h3>
<a href="javascript:alert(python.GetUnicodeString())">
python.GetUnicodeString()</a><br>
You should see a long dash in python 2.7.
<h3>Test creation of second browser</h3>
<a href="javascript:python.CreateSecondBrowser()">python.CreateSecondBrowser()</a>
<h3>Test int32, uint, long</h3>
<a href="javascript:alert(python.GetType(2147483647))">python.GetType(2147483647)</a><br>
<a href="javascript:alert(python.GetType(2147483648))">python.GetType(2147483648)</a> - here we get UINT from CEF so it is converted to long in Py2, int in Py3.<br>
<a href="javascript:alert(python.GetType(4294967295))">python.GetType(4294967295)</a> - uint limit.<br>
<a href="javascript:alert(python.GetType(4294967296))">python.GetType(4294967296)</a> - outside of uint limit, converted to float.<br>
<a href="javascript:alert(python.GetType(-2147483647))">python.GetType(-2147483647)</a><br>
<a href="javascript:alert(python.GetType(-2147483648))">python.GetType(-2147483648)</a><br>
<a href="javascript:alert(python.GetType(-2147483649))">python.GetType(-2147483649)</a> - here you get a FLOAT value, not long.<br>
<br>
TODO: do these tests the other way, from javascript to python.
<br>
<h3>Basic authentication</h3>
<input type=text value="http://127.0.0.1/cefpython/cefpython-src/cefpython/var/http_authentication.php" size=80 id=httpauth>
<input type=button value="Go" onclick="location.href=httpauth.value">
<br>
<h3>Frame.ExecuteJavascript()</h3>
<textarea id=jscode cols=50 rows=2>alert('test me [unicode: ąś]')</textarea><br>
<a href="javascript:python.ExecuteJavascript(jscode.value)">python.ExecuteJavascript(jscode.value)</a> - execute javascript from the textarea above.
<h3>Frames</h3>
<iframe src="cefsimple.html" name=simple></iframe>
<iframe src="cefsimple_onloaderror.html"></iframe>
<h3>Javascript bindings</h3>
See output in the console for the javascript bindings tests.<br>
Note: "window." is optional, you can just call "python.Test1()".<br>
<h4>Passing arguments</h4>
<a href="javascript:alert('Return value from python.Test1: '+python.Test1(100))">python.Test1(100)</a><br>
<a href="javascript:alert('Return value from python.Test2: '+JSON.stringify(python.Test2(100, 'This string was passed from javascript [unicode: ąś]', '')))">python.Test2(100, 'This string was passed from javascript [unicode: ąś]', '')</a> - python.Test2() should return: [1,2, [2.1, {'3': 3, '4': [5,6]}], unicode...]
<br><br>
<script>var array = [1]; array[100] = 100.01;</script>
<a href="javascript:python.Test1(array)">python.Test1(array)</a> (var array = [1]; array[100] = 100.01;) - the gap is filled with None values.<br>
<script>var object = {a: 1, '3': 33};</script>
<a href="javascript:python.Test1(object)">python.Test1(object)</a> (var object = {a: 1, '3': 33};)<br>
<br>
<script>var nested = [1,2, [3, -4, [5,6, [{7:7, 8: [9,10]}, 11]]]];</script>
<a href="javascript:python.Test1(nested)">python.Test1(nested)</a> (var nested = [1,2, [3, 4, [5,6, [{7:7, 8: [9,10]}, 11]]]];) - dictionary keys will be in a different order in Python.<br>
<br>
window.PyConfig =
<script>document.write(JSON.stringify(window.PyConfig));</script>
<br>
Now change PyConfig: <a href="javascript:window.PyConfig={'option1': false, 'option2': 40}">window.PyConfig={'option1': False, 'option2': 40}</a><br>
Call __browser.GetMainFrame().GetProperty("PyConfig"): <a href="javascript:python.PrintPyConfig()">python.PrintPyConfig()</a><br>
Try setting PyConfig during runtime using __browser.GetMainFrame().SetProperty(): <a href="javascript:python.ChangePyConfig()">python.ChangePyConfig()</a> (then call python.PrintPyConfig())
<h3>Javasript callbacks</h3>
<script>
function MyJSCallback(arg1, arg2, arg3, arg4, arg5)
{
alert("MyJSCallback() called\narg1="+JSON.stringify(arg1)+"\narg2="+JSON.stringify(arg2)+"\narg3="+JSON.stringify(arg3)+"\narg4="+JSON.stringify(arg4)+"\narg5="+JSON.stringify(arg5))
}
</script>
<a href="javascript:python.TestJavascriptCallback(MyJSCallback)">
python.TestJavascriptCallback(MyJSCallback)</a><br>
MyJSCallback alerts arguments.
<h3>Python callbacks</h3>
<p>See the output in the console.</p>
<script>
function JSCallbackForPythonCallback(pycallback)
{
pycallback("Calling pycallback via javascript's callback")
}
</script>
<a href="javascript:python.TestPythonCallbackThroughReturn()('some')">python.TestPythonCallbackThroughReturn()('some')</a><br>
<a href="javascript:python.TestPythonCallbackThroughJavascriptCallback(JSCallbackForPythonCallback)">python.TestPythonCallbackThroughJavascriptCallback(JSCallbackForPythonCallback)</a>
<h3>Errors</h3>
<p>Typically when you browse a webpage javascript errors appear in
the developer tools javascript console (in cefadvanced.py there
is a binding to F12 key for the developer tools popup).</p>
<h4>Global exception handler</h4>
<script>
function DoSomeError() {
asd()
}
</script>
<p>You can catch javascript errors programmatically by
using JavascriptContextHandler.OnUncaughtException() callback,
to see the complete stack trace you need to set the
"uncaught_exception_stack_size" ApplicationSettings option to
a value greater than 0, test it:<br>
<a href="javascript:DoSomeError()">
DoSomeError()</a>
</p>
<h4>Test error when calling javascript callback from python</h4>
<script>
function JsCallbackThrowingError()
{
throw new Error("some error message")
}
</script>
<a href="javascript:python.TestJavascriptCallback(JsCallbackThrowingError)">
python.TestJavascriptCallback(JsCallbackThrowingError)</a><br>
JsCallbackThrowingError throws new Error().
<h4>Infinite recursion</h4>
<a href="javascript:python.Test1(window)">python.Test1(window)</a><br>
You should see a python exception in the console (also in error.log),
as data structures can have maximum 8 levels of nesting.
<h3>Moving and resizing window</h3>
<a href="javascript:python.ResizeWindow()">python.ResizeWindow()</a> - cefwindow.MoveWindow(__browser.GetWindowID(), width=500, height=500)<br>
<a href="javascript:python.MoveWindow()">python.MoveWindow()</a> - cefwindow.MoveWindow(__browser.GetWindowID(), xpos=0, ypos=0)
<h3>Popups</h3>
<a href="javascript:window.open('cefsimple.html', '', 'width=600,height=400')">window.open('cefsimple.html')</a><br>
<a href="javascript:window.open('cefadvanced.html', '', 'width=600,height=400')">window.open('cefadvanced.html')</a>
<h3>Overwriting window.alert()</h3>
<pre>def Alert(self, msg):
print "python.Alert() called instead of window.alert()"
win32gui.MessageBox(__browser.GetWindowID(), msg, "python.Alert()")</pre>
<a href="javascript:window.alert('SOME ALERT!')">window.alert('SOME ALERT!')</a>
<br><br>
<pre>def ChangeAlertDuringRuntime(self):
__browser.GetMainFrame().SetProperty("alert", self.Alert2)</pre>
<a href="javascript:python.ChangeAlertDuringRuntime()">python.ChangeAlertDuringRuntime()</a> - now check window.alert() above, the messagebox style should be changed.
<h3>Find text on this page</h3>
<pre>def Find(self, searchText, findNext=False):
__browser.Find(1, searchText, forward=True, matchCase=False, findNext=findNext)</pre>
<input type=text id=searchText value="python"> <input type=button value="python.Find()" onclick="python.Find(document.getElementById('searchText').value)">
</body>
</html>