diff --git a/shell/browser/ui/cocoa/electron_ns_window.mm b/shell/browser/ui/cocoa/electron_ns_window.mm index 929631b091..ded8d8bcf9 100644 --- a/shell/browser/ui/cocoa/electron_ns_window.mm +++ b/shell/browser/ui/cocoa/electron_ns_window.mm @@ -205,7 +205,11 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) { // The WebContentsView is added a sibling of BaseWindow's contentView at // index 0 before it in the paint order - see // https://github.com/electron/electron/pull/41256. - auto* wcv = shell_->GetContentsView()->children().front().get(); + const auto& children = shell_->GetContentsView()->children(); + if (children.empty()) + return; + + auto* wcv = children.front().get(); if (!wcv) return; @@ -215,8 +219,8 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) { if (!ns_view) return; - auto* iwcv = (ElectronInspectableWebContentsView*)ns_view; - [iwcv redispatchContextMenuEvent:base::apple::OwnedNSEvent(event)]; + [static_cast(ns_view) + redispatchContextMenuEvent:base::apple::OwnedNSEvent(event)]; return; }