diff --git a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm index 6e0a50325d731..e53c6c9749f73 100644 --- a/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm +++ b/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm @@ -1637,7 +1637,15 @@ void NativeWidgetNSWindowBridge::FullscreenControllerTransitionComplete( UpdateWindowDisplay(); // Add any children that were skipped during the fullscreen transition. + // OrderChildren() may call -[NSWindow beginSheet:completionHandler:] for a + // deferred window-modal sheet child, which spins a nested run-loop that can + // close this window and free `this`. Guard with a WeakPtr, mirroring the fix + // in FullscreenControllerToggleFullscreen() (https://crbug.com/503792787). + auto weak_ptr = factory_.GetWeakPtr(); OrderChildren(); + if (!weak_ptr) { + return; + } host_->OnWindowFullscreenTransitionComplete(is_fullscreen); if (is_fullscreen && immersive_mode_controller_) {