Bug: [Headless] nsFilePicker::GtkFileChooserNew crash under automation
Status: RESOLVED
Priority: P3
Resolution: FIXED
Created: 2024-10-25 11:19:57+00:00
Resolved: 2024-11-04 21:35:28+00:00

Steps to reproduce:

I only have a Playwright reproduction so far, since the steps / stacktrace seems clear I didn't create an isolated one with Selenium and stock Firefox. See here for our details:

https://github.com/microsoft/playwright/issues/33257


Actual results:

It crashes with this backtrace:

```
(gdb) bt
#0  0x000077e8bbb9d7da in g_log_writer_default () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#1  0x000077e8b82f5b8f in glib_log_writer_func (flags=G_LOG_LEVEL_ERROR, fields=0x7ffc3437f6d0, n_fields=6, user_data=0x0) at /root/firefox/toolkit/xre/nsSigHandlers.cpp:210
#2  0x000077e8bbb95044 in g_log_structured_array () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#3  0x000077e8bbb952a8 in g_log_structured_standard () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#4  0x000077e8bc03425e in ??? () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#5  0x000077e8bbb10ff9 in g_type_create_instance () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#6  0x000077e8bbaf6a64 in ??? () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#7  0x000077e8bbaf8016 in g_object_new_with_properties () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#8  0x000077e8bbaf8f71 in g_object_new () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#9  0x000077e8bc144708 in ??? () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#10 0x000077e8bc1449a3 in gtk_style_new () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#11 0x000077e8bc14ac61 in gtk_widget_get_default_style () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#12 0x000077e8bc0d4d62 in ??? () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#13 0x000077e8bbb10fbb in g_type_create_instance () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#14 0x000077e8bbaf6a64 in ??? () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#15 0x000077e8bbaf8bc3 in g_object_new_valist () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#16 0x000077e8bbaf8f4f in g_object_new () at /lib/x86_64-linux-gnu/libgobject-2.0.so.0
#17 0x000077e8bbf0873f in gtk_file_chooser_dialog_new () at /lib/x86_64-linux-gnu/libgtk-3.so.0
#18 0x000077e8b79ea9a6 in nsFilePicker::GtkFileChooserNew (this=<optimized out>, title=0x7ffc343808bc "File Upload", parent=<optimized out>, action=<optimized out>, accept_label=0x0) at /root/firefox/widget/gtk/nsFilePicker.cpp:721
#19 0x000077e8b79ea20f in nsFilePicker::Open (this=0x77e8a5875120, aCallback=0x77e8a593adc0) at /root/firefox/widget/gtk/nsFilePicker.cpp:440
#20 0x000077e8b755f1cd in mozilla::dom::FilePickerParent::RecvOpen
    (this=0x77e8a3ed7380, aSelectedType=@0x7ffc34380aa6: 0, aAddToRecentDocs=<optimized out>, aDefaultFile=..., aDefaultExtension=..., aFilters=<optimized out>, aFilterNames=..., aRawFilters=..., aDisplayDirectory=..., aDisplaySpecialDirectory=..., aOkButtonLabel=..., aCapture=@0x7ffc343809f7: nsIFilePicker::captureNone) at /root/firefox/dom/ipc/FilePickerParent.cpp:276
#21 0x000077e8b7621e43 in mozilla::dom::PFilePickerParent::OnMessageReceived (this=0x77e8a3ed7380, msg__=<optimized out>) at /root/firefox/obj-build-playwright/ipc/ipdl/PFilePickerParent.cpp:307
#22 0x000077e8b75f4740 in mozilla::dom::PContentParent::OnMessageReceived (this=<optimized out>, msg__=...) at /root/firefox/obj-build-playwright/ipc/ipdl/PContentParent.cpp:6391
#23 0x000077e8b5042e4b in mozilla::ipc::MessageChannel::DispatchAsyncMessage (this=this@entry=0x77e8a53a0e80, aProxy=aProxy@entry=0x77e8a4f75be0, aMsg=...) at /root/firefox/ipc/glue/MessageChannel.cpp:1785
#24 0x000077e8b504226f in mozilla::ipc::MessageChannel::DispatchMessage (this=this@entry=0x77e8a53a0e80, aProxy=aProxy@entry=0x77e8a4f75be0, aMsg=...) at /root/firefox/ipc/glue/MessageChannel.cpp:1712
#25 0x000077e8b50425ee in mozilla::ipc::MessageChannel::RunMessage (this=0x77e8a53a0e80, aProxy=0x77e8a4f75be0, aTask=...) at /root/firefox/ipc/glue/MessageChannel.cpp:1503
#26 0x000077e8b5042a01 in mozilla::ipc::MessageChannel::MessageTask::Run (this=0x77e89b2aeeb0) at /root/firefox/ipc/glue/MessageChannel.cpp:1603
#27 0x000077e8b49d1efe in mozilla::RunnableTask::Run (this=0x77e8a586df00) at /root/firefox/xpcom/threads/TaskController.cpp:618
#28 0x000077e8b49ced7a in mozilla::TaskController::DoExecuteNextTaskOnlyMainThreadInternal (this=this@entry=0x77e8bdc9a650, aProofOfLock=...) at /root/firefox/xpcom/threads/TaskController.cpp:945
#29 0x000077e8b49ce2c7 in mozilla::TaskController::ExecuteNextTaskOnlyMainThreadInternal (this=0x77e8bdd00018, this@entry=0x77e8bdc9a650, aProofOfLock=...) at /root/firefox/xpcom/threads/TaskController.cpp:768
#30 0x000077e8b49ce4b8 in mozilla::TaskController::ProcessPendingMTTask (this=0x77e8bdc9a650, aMayWait=false) at /root/firefox/xpcom/threads/TaskController.cpp:554
#31 0x000077e8b49d34cf in mozilla::TaskController::TaskController()::$_0::operator()() const (this=<optimized out>) at /root/firefox/xpcom/threads/TaskController.cpp:268
#32 mozilla::detail::RunnableFunction<mozilla::TaskController::TaskController()::$_0>::Run() (this=<optimized out>) at /root/firefox/xpcom/threads/nsThreadUtils.h:548
#33 0x000077e8b49de35c in nsThread::ProcessNextEvent (this=0x77e8bdc88680, aMayWait=<optimized out>, aResult=0x7ffc34382057) at /root/firefox/xpcom/threads/nsThread.cpp:1155
#34 0x000077e8b49e1bea in NS_ProcessNextEvent (aThread=0x77e8bdd00018, aThread@entry=0x77e8bdc88680, aMayWait=false) at /root/firefox/xpcom/threads/nsThreadUtils.cpp:480
#35 0x000077e8b50453e7 in mozilla::ipc::MessagePump::Run (this=0x77e8bdcf7dc0, aDelegate=0x77e8bdc8a740) at /root/firefox/ipc/glue/MessagePump.cpp:85
#36 0x000077e8b4ffb2b7 in MessageLoop::RunInternal (this=0x0) at /root/firefox/ipc/chromium/src/base/message_loop.cc:370
#37 MessageLoop::RunHandler (this=0x0) at /root/firefox/ipc/chromium/src/base/message_loop.cc:363
#38 MessageLoop::Run (this=0x0) at /root/firefox/ipc/chromium/src/base/message_loop.cc:345
#39 0x000077e8b7941d86 in nsBaseAppShell::Run (this=0x77e8b122bb80) at /root/firefox/widget/nsBaseAppShell.cpp:148
#40 0x000077e8b79ce3b7 in nsAppShell::Run (this=0x77e8b122bb80) at /root/firefox/widget/gtk/nsAppShell.cpp:469
#41 0x000077e8b823dec3 in nsAppStartup::Run (this=0x77e8b121e9c0) at /root/firefox/toolkit/components/startup/nsAppStartup.cpp:296
#42 0x000077e8b82ef1b9 in XREMain::XRE_mainRun (this=this@entry=0x7ffc34382300) at /root/firefox/toolkit/xre/nsAppRunner.cpp:5809
#43 0x000077e8b82ef8f7 in XREMain::XRE_main (this=this@entry=0x7ffc34382300, argc=argc@entry=7, argv=argv@entry=0x7ffc34383658, aConfig=...) at /root/firefox/toolkit/xre/nsAppRunner.cpp:6034
#44 0x000077e8b82efd78 in XRE_main (argc=7, argv=0x7ffc34383658, aConfig=...) at /root/firefox/toolkit/xre/nsAppRunner.cpp:6106
#45 0x000059863c2f2189 in do_main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at /root/firefox/browser/app/nsBrowserApp.cpp:233
#46 main (argc=7, argv=0x7ffc34383658, envp=<optimized out>) at /root/firefox/browser/app/nsBrowserApp.cpp:470
```




Expected results:

I should not crash.

Its probably similar to https://bugzilla.mozilla.org/show_bug.cgi?id=1870924 and we need a IsHeadless check like in https://github.com/mozilla/gecko-dev/blob/b2d5ed9e8997e0c95c9243ffebd8573daade7eb3/widget/windows/nsFilePicker.cpp#L873-L876 but in the Gkt code: https://github.com/mozilla/gecko-dev/blob/b2d5ed9e8997e0c95c9243ffebd8573daade7eb3/widget/gtk/nsFilePicker.cpp#L420