Hi all,
I’m building a Chrome native‑messaging host on Windows that sometimes needs to pop up a MessageBox (or similar dialog, e.g. for scanner UI or reporting errors). Right now, when it tries to call SetForegroundWindow, Windows refuses and just flashes the taskbar button, because Chrome still owns the foreground.
I dug into Chromium’s code and found this:
However, my host is launched from a service‑worker background page, so --parent-window=0 every time.
I have tried locating how to change this behavior and tried flipping the NativeHostsExecutablesLaunchDirectly flag (which also controls start_hidden), but I am failing to find anything useful that will pass a valid HWND.
The current workaround I’ve seen is to briefly open a 1x1 popup so Chrome will pass its window handle:
That hack may work (I have not tried it yet), but it feels brittle:
Is there a supported API for forcing Chrome to hand me its window handle, even from a background script?
Am I missing another flag or context under which --parent-window is set?
Are there “official” patterns (beyond toast popups or UIAccess manifests) that extension authors use to let native‑host dialogs take focus without extra user clicks?
Any pointers or "tried-and-true" recipes you’ve used would be hugely appreciated!
Thanks
