Adding cookies to wxPython sample

277 views
Skip to first unread message

mkimb...@gmail.com

unread,
May 30, 2017, 9:36:12 PM5/30/17
to CEF Python
I'm trying to add cookie support to the wxPython sample so it can remember user name and password across sessions. The CookieManager class doc says an example is in wxPython.py but I'm pretty sure this hasn't been added.

The obvious first step is to specify a cache dir with settings before calling cef.Inititialize:

settings['cache_path'] = cacheDir

After running the program I can see a 'Cookies' file created in the cache but it doesn't appear to be used next time I run the program.

The docs say that 'persist_session_cookies' defaults to True and adding this to settings has no effect.

Do I need to create a request context handler? Manually call VisitUrlCookies and call a function on it?

Thanks,
Matt

Czarek Tomczak

unread,
May 31, 2017, 12:43:56 AM5/31/17
to CEF Python
It works fine for me. Modified wxpython.py example by adding "cache_path" setting and run http://www.html-kit.com/tools/cookietester/ to create cookie.

[wxpython.py] CEF Python 58.0
[wxpython.py] Python 2.7.6 64bit
[wxpython.py] wxPython 2.8.12.1 (gtk2-unicode)

Czarek Tomczak

unread,
May 31, 2017, 12:44:13 AM5/31/17
to CEF Python
Tested on Linux.

25kimb...@mbusdapps.org

unread,
May 31, 2017, 2:21:55 PM5/31/17
to CEF Python
Hi Czarek,

I tried again with the cookietester URL you provided. I'm running Windows 10. My only modifications to wxpython.py is the test url and the addition of this line:

settings['cache_path'] = os.path.join( os.environ['TMP'], 'cefpython' )

Here's the program output:
[wxpython.py] CEF Python 57.0
[wxpython.py] Python 2.7.11 64bit
[wxpython.py] wxPython 4.0.0a1 msw (phoenix)
[wxpython.py] OnClose called

- Starting with an empty cache, I launch the program
- The web page loads
- "Number of cookies received: 0" is displayed
- I click "Set Test Cookie"
- After a few seconds the web page reloads...
- "Number of cookies received: 1" is displayed
- Now I close the program by clicking the X button
- The 'Cookies' file in the cache dir is 7kb
- Run the program again
- After the page loads "Number of cookies received: 0" is displayed

My best guess is that cef.Shutdown() isn't flushing the file because it did work once work when I set a break point on that line in the debugger and step over it. After that the size of Cookies was 10kb, I could see settings from the website stored when viewing the file, and the cookie loaded when I re-launched the program.

-Matt


Czarek Tomczak

unread,
May 31, 2017, 2:37:48 PM5/31/17
to CEF Python
Hi Matt,

Related issue: https://github.com/cztomczak/cefpython/issues/158

Please run example (with the cache_path change only) with the --debug flag and attach debug.log file.

Try calling either self.browser.CloseBrowser() or self.browser.CloseBrowser(True) in OnClose before self.browser.ParentWindowWillClose().

25kimb...@mbusdapps.org

unread,
May 31, 2017, 7:23:56 PM5/31/17
to CEF Python
Hi Czarek,

Adding a call to CloseBrowser had no effect.

I added these lines:
settings['debug'] = True
settings['log_file'] = '{}\\CefPython.log'.format(cacheDir)

ran again, and just this line appeared in the log file:

[0531/161943.938:ERROR:child_thread_impl.cc(762)] Request for unknown Channel-associated interface: ui::mojom::GpuMain

-Matt

25kimb...@mbusdapps.org

unread,
May 31, 2017, 7:30:52 PM5/31/17
to CEF Python
With Info enabled:

[0531/162941.141:INFO:cef_log.cpp(8)] [Browser process] CefBrowser::CloseBrowser(True)

[0531/162942.186:INFO:cef_log.cpp(8)] [Browser process] Shutdown()

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] LifespanHandler_OnBeforeClose

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#2]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#-4]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#17]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#16]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#15]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#14]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#13]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#12]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#19]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyFrames[1#18]

[0531/162942.196:INFO:cef_log.cpp(8)] [Browser process] del g_pyBrowsers[1]

[0531/162942.396:INFO:cef_log.cpp(8)] [Browser process] CefShutdown()

Czarek Tomczak

unread,
Jun 1, 2017, 12:26:27 AM6/1/17
to CEF Python
Does it work in other examples? qt.py, hello_world.py, gtk2.py, tkinter_.py?

25kimb...@mbusdapps.org

unread,
Jun 1, 2017, 12:51:05 PM6/1/17
to CEF Python
I reproduced the issue in qt.py and hello_world.py

Czarek Tomczak

unread,
Jun 2, 2017, 2:11:36 AM6/2/17
to CEF Python
Please also test in cefclient sample application to see if this is upstream issue.

Version to download:
3.2987.1601.gf035232

https://github.com/cztomczak/cefpython/blob/master/docs/Knowledge-Base.md#feature-x-works-in-google-chrome-but-doesnt-work-in-cef-python

Run cefclient with this flag (to set webcache/ local directory):
cefclient.exe --cache-path=webcache

Czarek Tomczak

unread,
Jun 8, 2017, 8:03:58 AM6/8/17
to CEF Python
Created issue: https://github.com/cztomczak/cefpython/issues/365

More testing is still required to know whether this is an upstream issue.
Reply all
Reply to author
Forward
0 new messages