-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WinForms Example - File > Close Tab does not allow a fetch to clear cookies on page termination but CTRL + W hotkey does #4846
Comments
Does cefsharp/CefSharp.MinimalExample#147 (comment) work in the context of the minimal example? |
Hey @amaitland , when I wrote that other issue I was only looking at network traffic and wasn't testing the full use case (the write up above). When I tested the demo site with the minimal example, I noticed (1) the example doesn't support multiple tabs and (2) it doesn't support persisting cookies across sessions, at least when running from source in VS. I do think that whatever conclusion we come to here could apply to the minimal example. |
@amaitland , I did manage to test this in the minimal example. It does not show the same issue, at least in my test of closing/re-opening the minimal example. When I have no handler set the cookie persists, but I can successful clear it with both the client and server handlers, regardless of whether I put in my update from the other issue (removing the browser from the parent control before disposing the browser). PS - I had to update my site to set a cookie expiration. Without that I wasn't seeing my cookies persist between runs in the first place. Just realized that today. |
Great, thanks for confirming. When
You can try deferring |
Hi @amaitland , I'm not sure whether to open another issue for this, but I've made some progress on diagnosing our issue. I think there is some sort of race condition happening between the main CefSharp process and the subprocesses. Specifically, if I run my website within the CefSharp.WinForms.Example project, I can inconsistently reproduce an issue where my SetCookie response (triggered from a fetch request within an unload or pagehide handler) does not always get set back into the cookie cache for the browser. I'm actually not sure if the handler is inconsistently firing, or if it is firing and not triggering the fetch in time, because I haven't figured out how to make HTTPS interception work with Fiddler. The example doesn't seem to go to the system proxy. I think this is a race condition because of how inconsistent the issue is, though I'm trying my best to run the same test every time. I'm not sure where to go from here, but I've attached a couple of debug logs: one from a successful test and one from a failed one . They both include log lines that mention messages sent to detached frames, and notably we are triggering these requests from within an iframed page:
Success_3_debug_log.txt Any advice here would be appreciated! |
From memory the example only calls
Did you try this? |
Is there an existing issue for this?
CefSharp Version
v124.3.80
Operating System
Windows 10
Architecture
x64
.Net Version
net472
Implementation
WinForms
Reproduction Steps
In a CefSharp WinForms application hosting one of my company's web pages, we see an issue where closing a browser tab from the WinForms application will trigger page termination events but does not update the browser's cookie cache based on any fetch responses triggered during those events. For example, we register an
unload
handler like this (and the approach works in Chrome/Edge):Where the fetch response has a SetCookie header that clears the existing one.
I was able to reproduce this in the CefSharp.WinForms.Example and was hoping to find a workaround/fix to this that we could use. What's strange is that if you instead close the tab with the
CTRL+W
hotkey, the fetch responses are able to update the cookie cache!With the CefSharp.WinForms.Example project and a razor page that demonstrates the cookie handling I can do the following workflow:
dotnet run
itFile > Close Tab
If I repeat the above, but in step 4 use the
CTRL+W
hotkey instead ofFile > CloseTab
to close the tab, the cookies do get cleared! In this case there is a noticeable lag before the tab control/page is completely closed (probably something that is waiting on the fetch call).The cookies are still not cleared if, in step 4, I swap the
unload
event to thepagehide (when not persisted)
event. This swaps what event we fire the fetch on, and forpagehide
swaps to a handler function that respects theevent.persisted
value:I bring this up because I realize
unload
is flagged as deprecated, but its replacement ofpagehide
doesn't work either. For reference:The cookies are cleared if, in step 4, I select the "CLIENT" handler instead of "SERVER". In this case, this swaps the handler to just set document.cookie instead of using a fetch response to do so. It seems that if the handlers can run immediately, then they have time to clear the cookies:
Note this isn't a workaround in our case since we want the server to also invalidate the session it has for the cookie before we clear it from the browser.
Expected behavior
Closing a browser tab from WinForms should support the same termination handling as closing from the browser process (what I assume
CTRL+W
is doing thatFile > Close Tab
is not in the example).Actual behavior
Closing a browser tab from WinForms does not support the fetch > clear cookies workflow on termination.
Regression?
I've been having build issues (so many VS errors) and have only been able to test things in v124.3.80.
Known Workarounds
No response
Does this problem also occur in the CEF Sample Application
No
Other information
For
cefclient
I did not see the issue when I triedTests > New Window
(orPopup Window
) and treat that like the tab to close.The text was updated successfully, but these errors were encountered: