Repository: electron/electron (language: cpp)

Issue:
DCHECK in autofill relating to zero-sized windows on macOS
Version: 6932e02eb862080f56d5ae811f3f3efce4309221
OS: macOS

No repro unfortunately, observed running Slack under a debug build of Electron.

```
[29366:1123/155917.793910:FATAL:native_widget_ns_window_bridge.mm(499)] Check failed: !clamped_content_size.IsEmpty(). Zero-sized windows not supported on Mac
0   Electron Framework                  0x0000000120a74569 base::debug::CollectStackTrace(void**, unsigned long) + 9
1   Electron Framework                  0x00000001206fc9f3 base::debug::StackTrace::StackTrace() + 19
2   Electron Framework                  0x000000012076cd0a logging::LogMessage::~LogMessage() + 1146
3   Electron Framework                  0x000000012076fa6e logging::LogMessage::~LogMessage() + 14
4   Electron Framework                  0x0000000128d8b21f remote_cocoa::NativeWidgetNSWindowBridge::SetBounds(gfx::Rect const&, gfx::Size const&) + 799
5   Electron Framework                  0x00000001348ef62a views::NativeWidgetMacNSWindowHost::SetBoundsInScreen(gfx::Rect const&) + 794
6   Electron Framework                  0x0000000134923cd1 views::NativeWidgetMac::SetBounds(gfx::Rect const&) + 289
7   Electron Framework                  0x000000010fb72e49 electron::AutofillPopupView::Show() + 1401
8   Electron Framework                  0x000000010f8e45f8 electron::AutofillPopup::CreateView(content::RenderFrameHost*, content::RenderFrameHost*, bool, views::View*, gfx::RectF const&) + 1336
9   Electron Framework                  0x000000010f7a376c electron::AutofillDriver::ShowAutofillPopup(gfx::RectF const&, std::__1::vector<std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator<unsigned short> >, std::__1::allocator<std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator<unsigned short> > > > const&, std::__1::vector<std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator<unsigned short> >, std::__1::allocator<std::__1::basic_string<unsigned short, base::string16_internals::string16_char_traits, std::__1::allocator<unsigned short> > > > const&) + 1244
10  Electron Framework                  0x000000011e85c519 electron::mojom::ElectronAutofillDriverStubDispatch::Accept(electron::mojom::ElectronAutofillDriver*, mojo::Message*) + 1577
[...]
```


Discussion / hints:
Hey @nornagon 
I also went into the same where a Dcheck is stopping me to create zero-sized invisible windows 
```js
new BrowserWindow ({ width: 0, height: 0, show: false})
```
I have opened a CL with chromium to get their point of view on this issue. [Ref](https://chromium-review.googlesource.com/c/chromium/src/+/3291098)
Hi from the Chrome Mac team, and from the individual who added the prohibition of empty windows many years ago.

When we added that `DCHECK` we did have to go through Chromium code and make sure that no windows were created empty. In many cases, just creating the window as a 1×1 window rather than as an empty one was sufficient. For the `electron::AutofillDriver::ShowAutofillPopup` case, that’s what I’d recommend.

For the `BrowserWindow` construction case, I would extend the input value validation to reject empty windows. If your underlying platform doesn’t allow for empty windows, you should reject such values rather than just pass those values to the underlying platform and crash.
This issue has been automatically marked as stale. **If this issue is still affecting you, please leave any comment** (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the [latest version of Electron](https://www.electronjs.org/releases/stable) or in the [beta](https://www.electronjs.org/releases/beta)—please include it with your comment!

Fix patch:
diff --git a/shell/browser/ui/views/autofill_popup_view.cc b/shell/browser/ui/views/autofill_popup_view.cc
index fd2e50921460a..068c1a0f61e38 100644
--- a/shell/browser/ui/views/autofill_popup_view.cc
+++ b/shell/browser/ui/views/autofill_popup_view.cc
@@ -224,6 +224,9 @@ void AutofillPopupView::DoUpdateBoundsAndRedrawPopup() {
   if (!popup_)
     return;
 
+  // Clamp popup_bounds_ to ensure it's never zero-width.
+  popup_->popup_bounds_.Union(
+      gfx::Rect(popup_->popup_bounds_.origin(), gfx::Size(1, 1)));
   GetWidget()->SetBounds(popup_->popup_bounds_);
 #if BUILDFLAG(ENABLE_OSR)
   if (view_proxy_.get()) {


Test patch: