diff --git a/chrome/browser/ui/views/digital_credentials/digital_identity_safety_interstitial_controller_desktop.cc b/chrome/browser/ui/views/digital_credentials/digital_identity_safety_interstitial_controller_desktop.cc index 462aebd0d0648..2bae1d0449fcb 100644 --- a/chrome/browser/ui/views/digital_credentials/digital_identity_safety_interstitial_controller_desktop.cc +++ b/chrome/browser/ui/views/digital_credentials/digital_identity_safety_interstitial_controller_desktop.cc @@ -171,11 +171,20 @@ void DigitalIdentitySafetyInterstitialControllerDesktop::ShowInterstitialImpl( } dialog_widget_ = constrained_window::ShowWebModal( dialog_model_builder.Build(), &web_contents); + // ShowWebModal() can synchronously re-enter (via SetWebContentsBlocked → + // ExitFullscreen, which on some platforms spins a nested run loop) and + // destroy `web_contents`. `this` survives because `callback_` (which owns + // the controller) is only run via PostTask in OnDialogClosed(), but the + // by-reference `web_contents` parameter may now dangle. Re-check the + // WeakPtr captured in ShowInterstitial() before any further use. + if (!web_contents_) { + return; + } extensions::SecurityDialogTracker::GetInstance()->AddSecurityDialog( dialog_widget_); close_on_navigation_observer_ = std::make_unique(); - close_on_navigation_observer_->Observe(web_contents); + close_on_navigation_observer_->Observe(*web_contents_); } void DigitalIdentitySafetyInterstitialControllerDesktop::OnDialogClosed(