Brave Browser Crashes After Shutdown in Linux (Kubuntu), Fixed with Script

Description of the issue:
The browser seems to crash sometimes if it is still open when Linux shuts down.

How can this issue be reproduced?

  1. Open Brave
  2. Restart or shut down the computer
  3. Start Brave, and it complains that it crashed

Expected result:
Brave starts and restores tabs

Brave Version( check About Brave):
Brave 1.74.50
Kubuntu 24.10
Installed via Flatpak

Additional Information:
I think the problem is that Linux ends the Brave processes in the wrong order, which causes the browser to crash. When I kill what I believe is the original process before shutdown, Brave starts without complaints the next time.
Now, I have KDE execute this script every time before logout:

#!/bin/bash

Find Brave process with specific command line

PID=$(ps aux | grep “[b]rave --disable-features=WebAssemblyTrapHandler,DesktopPWAsRunOnOsLogin --no-default-browser-check” | awk ‘{print $2}’)

if [ -z “$PID” ]; then
echo “Brave is not running with the specified command.”
exit 1
else
# Kill the found process
kill -15 $PID
echo “Brave process (PID: $PID) has been terminated.”
fi

I know there are similar posts already, but I didn’t come across one that resolved this specific issue (not that this is a real fix, either).