diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index a86c66cc5a1d34f437abb9febf99ba8bb9a485fc..7e9a4e41d78a46e4207d7cb0f70399261dce5ca0 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -85,6 +85,13 @@ BrowserContextAdapter::BrowserContextAdapter(bool offTheRecord) , m_httpCacheMaxSize(0) { WebEngineContext::current(); // Ensure the WebEngineContext has been initialized + + // Mark the context as live. This prevents the use-after-free DCHECK in + // AssertBrowserContextWasntDestroyed from being triggered when a new + // BrowserContextQt object is allocated at the same address as a previously + // destroyed one. Needs to be called after WebEngineContext initialization. + BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(m_browserContext.data()); + content::BrowserContext::Initialize(m_browserContext.data(), toFilePath(dataPath())); } @@ -98,6 +105,13 @@ BrowserContextAdapter::BrowserContextAdapter(const QString &storageName) , m_httpCacheMaxSize(0) { WebEngineContext::current(); // Ensure the WebEngineContext has been initialized + + // Mark the context as live. This prevents the use-after-free DCHECK in + // AssertBrowserContextWasntDestroyed from being triggered when a new + // BrowserContextQt object is allocated at the same address as a previously + // destroyed one. Needs to be called after WebEngineContext initialization. + BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(m_browserContext.data()); + content::BrowserContext::Initialize(m_browserContext.data(), toFilePath(dataPath())); }