Skip to content

Commit 8b7a4c8

Browse files
committed
obs-browser: flush panel cookie store on exit
If cookie store is not flushed, state might become inconsistent: reading from the cookies file will become impossible. No errors will be returned, yet no information will be available, and no information will be stored: the cookie manager will appear to be empty at all times and the `Cookies` file modified date will not update moving forward. This will result, for example, in Twitch chat window re-opening for users which connected their Twitch account, but not having the `auth-token` cookie available: once the user will try to send a message to the chat, they will be redirected to Twitch login screen.
1 parent d5b6812 commit 8b7a4c8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

obs-browser-plugin.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ bool hwaccel = false;
6060

6161
/* ========================================================================= */
6262

63+
static std::mutex cookie_managers_mutex;
64+
static std::vector<CefRefPtr<CefCookieManager>> cookie_managers;
65+
66+
void register_cookie_manager(CefRefPtr<CefCookieManager> cm)
67+
{
68+
std::lock_guard<std::mutex> guard(cookie_managers_mutex);
69+
70+
cookie_managers.emplace_back(cm);
71+
}
72+
73+
static void flush_cookie_managers()
74+
{
75+
std::lock_guard<std::mutex> guard(cookie_managers_mutex);
76+
77+
for (auto cm : cookie_managers) {
78+
if (cm->FlushStore(nullptr)) {
79+
blog(LOG_INFO, "Flushed cookie store");
80+
}
81+
else {
82+
blog(LOG_WARNING,
83+
"Failed flushing cookie store");
84+
}
85+
}
86+
}
87+
88+
/* ========================================================================= */
89+
6390
class BrowserTask : public CefTask {
6491
public:
6592
std::function<void()> task;
@@ -500,6 +527,8 @@ bool obs_module_load(void)
500527

501528
void obs_module_unload(void)
502529
{
530+
flush_cookie_managers();
531+
503532
if (manager_thread.joinable()) {
504533
while (!QueueCEFTask([] () {CefQuitMessageLoop();}))
505534
os_sleep_ms(5);

panel/browser-panel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ extern bool QueueCEFTask(std::function<void()> task);
1313
extern "C" void obs_browser_initialize(void);
1414
extern os_event_t *cef_started_event;
1515

16+
void register_cookie_manager(CefRefPtr<CefCookieManager> cm);
17+
1618
std::mutex popup_whitelist_mutex;
1719
std::vector<PopupWhitelistInfo> popup_whitelist;
1820
std::vector<PopupWhitelistInfo> forced_popups;
@@ -83,6 +85,8 @@ struct QCefCookieManagerInternal : QCefCookieManager {
8385
if (!cm)
8486
throw "Failed to create cookie manager";
8587

88+
register_cookie_manager(cm);
89+
8690
rch = new QCefRequestContextHandler(cm);
8791

8892
rc = CefRequestContext::CreateContext(

0 commit comments

Comments
 (0)