diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc index 03fe97357b5c8..3673a6c4d6caf 100644 --- a/chrome/browser/printing/print_view_manager.cc +++ b/chrome/browser/printing/print_view_manager.cc @@ -420,7 +420,14 @@ void PrintViewManager::OnScriptedPrintPreviewCallback( // Running a dialog causes an exit to webpage-initiated fullscreen. // https://crbug.com/41322524 if (web_contents()->IsFullscreen()) { + // ExitFullscreen() may spin the message loop and synchronously destroy the + // WebContents (and therefore `this`, which is WebContentsUserData). See + // crbug.com/1506535, crbug.com/498752242. + auto weak_this = weak_factory_.GetWeakPtr(); web_contents()->ExitFullscreen(true); + if (!weak_this) { + return; + } } auto* dialog_controller = PrintPreviewDialogController::GetInstance();