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
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
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
[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()