From 955af5abc3f0521c01ba0d02c4c5b087ac86498f Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 25 Apr 2023 11:30:16 +0200 Subject: [PATCH] fix: crash on missing `RenderWidgetHostView` (#38100) chore: fix crash on missing RenderWidgetHostView --- .../electron_inspectable_web_contents_view.mm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/shell/browser/ui/cocoa/electron_inspectable_web_contents_view.mm b/shell/browser/ui/cocoa/electron_inspectable_web_contents_view.mm index 1790ed888737b..3c8a73fe012e1 100644 --- a/shell/browser/ui/cocoa/electron_inspectable_web_contents_view.mm +++ b/shell/browser/ui/cocoa/electron_inspectable_web_contents_view.mm @@ -287,12 +287,14 @@ - (void)redispatchContextMenuEvent:(NSEvent*)event { // Temporarily pretend that the WebContents is fully non-draggable while we // re-send the mouse event. This allows the re-dispatched event to "land" // on the WebContents, instead of "falling through" back to the window. - api_contents->SetForceNonDraggable(true); - BaseView* contentsView = (BaseView*)contents->GetRenderWidgetHostView() - ->GetNativeView() - .GetNativeNSView(); - [contentsView mouseEvent:event]; - api_contents->SetForceNonDraggable(false); + auto* rwhv = contents->GetRenderWidgetHostView(); + if (rwhv) { + api_contents->SetForceNonDraggable(true); + BaseView* contentsView = + (BaseView*)rwhv->GetNativeView().GetNativeNSView(); + [contentsView mouseEvent:event]; + api_contents->SetForceNonDraggable(false); + } } }