diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 97f0e515d6acbb493a1d70fc996025d6ce5d2f93..5e9157069f13bb49266fddbb257b34eec1256a67 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -97,6 +97,7 @@ content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents if (targetAdapter) target = targetAdapter->webContents(); } + Q_ASSERT(target); content::NavigationController::LoadURLParams load_url_params(params.url); load_url_params.referrer = params.referrer; diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index dbbac1aedff2fc898bd37ee4fd73701c3c38dfcc..f10833b9b803c943c16f643836ab41564cfe0fc4 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -279,9 +279,14 @@ void QWebEnginePagePrivate::adoptNewWindow(QSharedPointer<WebContentsAdapter> ne if (newPage->d_func() == this) { // If createWindow returns /this/ we must delay the adoption. Q_ASSERT(q == newPage); - QTimer::singleShot(0, q, [this, newPage, newWebContents, initialGeometry] () { - adoptNewWindowImpl(newPage, newWebContents, initialGeometry); - }); + // WebContents might be null if we just opened a new page for navigation, in that case + // avoid referencing newWebContents so that it is deleted and WebContentsDelegateQt::OpenURLFromTab + // will fall back to navigating current page. + if (newWebContents->webContents()) { + QTimer::singleShot(0, q, [this, newPage, newWebContents, initialGeometry] () { + adoptNewWindowImpl(newPage, newWebContents, initialGeometry); + }); + } } else { adoptNewWindowImpl(newPage, newWebContents, initialGeometry); }