focus problem invoking firefox with createprocess

UNCONFIRMED
Unassigned

Status

()

Firefox
General
UNCONFIRMED
8 years ago
3 years ago

People

(Reporter: Shark, Unassigned)

Tracking

3.6 Branch
x86
Windows XP
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

8 years ago
User-Agent:       Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; User-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; http://bsalsa.com) ; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Build Identifier: 3.6 final (same problem also in 3.0-3.5)

As I understand loadDivertedInBackground option (default false, I set it to true with about:config) should prevent Firefox from getting focus when an external application launches a URL with Firefox.

With loadDivertedInBackground false (default) the Firefox window gets focus. With loadDivertedInBackground true the Firefox window gets NO focus (correctly). The problem is that instead the focus goes to an invisible window of the class FirefoxMessageWindow. In other words, the focus is taken from the app that was active before and goes to nirvana, since an invisible window cannot handle it.

To reproduce:

Use the Win32 API function CreateProcess() to launch Firefox.


Reproducible: Always

Steps to Reproduce:
1.Use the Win32 API function CreateProcess() to launch Firefox
2.After this use the API function GetForeGroundWindow() and you will see the handle of FirefoxMessageWindow is returned.
3.This can be checked with the GetClassName() function.

Actual Results:  
FirefoxMessageWindow steals focus from the active application.

Expected Results:  
FirefoxMessageWindow should never get focus, since it's a hidden messaging window.

Do not steal focus with loadDivertedInBackground == true :)

Comment 1

8 years ago
You assumption about that setting is incorrect. When you open a web page from an external app Firefox will have focus.  A new tab will open for that web page.  The setting determines if that new tab will be opened in the background or become the new current tab.

http://kb.mozillazine.org/About:config_entries

browser.tabs.loadDivertedInBackground

Determines behavior of pages normally meant to open in a new window (such as target="_blank" or from an external program), but that have instead been loaded in a new tab.
True: Load the new tab in the background, leaving focus on the current tab
False (default): Load the new tab in the foreground, taking the focus from the current tab.
Note: Setting this preference to True will still bring the browser to the front when opening links from outside the browser.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → INVALID

Updated

8 years ago
Status: RESOLVED → VERIFIED
(Reporter)

Comment 2

8 years ago
> Note: Setting this preference to True will still bring the browser to the front
> when opening links from outside the browser.

This is definitely not true. I've tested it again 2 minutes ago with Firefox 3.6 on WindowsXP SP3.

1. test: loadDivertedInBackground = false (default)

Open Firefox. Go to another app (so that Firefox window is deactivated) and launch a URL externally (I'm doing it with CreateProcess).

Result: Firefox takes focus back

2. test: loadDivertedInBackground = true

Open Firefox. Go to another app (so that Firefox window is deactivated) and launch a URL externally (I'm doing it with CreateProcess).

Result: Firefox gets NO focus, the Firefox window goes NOT to front and is NOT activated (contrary to your statement). The focus is still removed from the app that had the focus before, but it is set to a window of the class FirefoxMessageWindow, which is hidden. The result is that focus is completely lost for all applications.

It's always reproducible.

Comment 3

8 years ago
Dao 

Do you know what the behavior for loadDivertedInBackground = true is supposed to be?  Is the browser window supposed to get focus or not?
I don't know...

(In reply to comment #2)
> Result: Firefox gets NO focus, the Firefox window goes NOT to front and is NOT
> activated (contrary to your statement).

I can confirm this.

> The focus is still removed from the app
> that had the focus before, but it is set to a window of the class
> FirefoxMessageWindow, which is hidden. The result is that focus is completely
> lost for all applications.

I'm not seeing this. The other application remains focused over here.

Comment 5

8 years ago
(In reply to comment #4)
Ok.  I had found this changeset and was hoping you'd know.
http://hg.mozilla.org/mozilla-central/rev/d05dc3d31c75

The behavior of opening URLs from other applications seems to have changed from earlier versions of Firefox (maybe versions 1 and/or 2) where the browser window would get focus from the other app but the new tab would not get focus.  But the current behavior does make more sense.  I guess the mozillazine knowledge base will need to be updated.

But I also see the focus remaining with the other application when opening a URL from that application with loadDivertedInBackground = true.  I used MS Word and ctrl-clicked on a URL, and I tried opening a link from Thunderbird.  I think the createprocess method used here is the difference.  It's different from the browser being invoked to open a URL from another app. AFAIK in that case the app goes to the OS to ask for a URL to be opened.  And the OS invokes Firefox to open it.
Status: VERIFIED → UNCONFIRMED
Resolution: INVALID → ---
Summary: loadDivertedInBackground option not working correctly → focus problem invoking firefox with createprocess
(Reporter)

Comment 6

8 years ago
>I think the createprocess method used here is the difference.
> It's different from the browser being invoked to open a URL from another app

Is there any other way to open an URL with Firefox from an external application besides using CreateProcess()?

I think also CreateProcess() is the problem here, as Firefox seems also to be the only Application that ignores all SW_ directives. E.g. you cannot start Firefox minimized using CreateProcess(), as passing SW_HIDE is ignored (I've tested all 12 SW_ options and none work, all 12 work with Notepad.exe).

Comment 7

8 years ago
Well your assuming that Firefox is installed.  A safer, more user friendly way would be to use the OS to open the default web browser.  For that you can use ShellExecute:

http://support.microsoft.com/kb/224816
http://msdn.microsoft.com/en-us/library/bb762153%28VS.85%29.aspx
(Reporter)

Comment 8

8 years ago
No, I'm not assuming it's installed, I'm checking of course first if it's there.

But ShellExecute won't solve the problem at all. ShellExecute is a wrapper for CreateProcess(), it makes an internal CreateProcess() call, so the result will stay exactly the same. To make sure I've tested it few minutes ago. Focus is still lost from my application window and Firefox does not get it either. All SW_ paratemeters are also ignored.
(Reporter)

Comment 9

8 years ago
p.s.

My application lets the user choose whether to launch IE, Firefox or the default system browser, so it is user friendly.
(Reporter)

Comment 10

8 years ago
What's the current status of the bug? I'm asking because it was set prematurely to solved before.

Updated

7 years ago
Version: unspecified → 3.6 Branch

Comment 11

6 years ago
I'm having the same problem in Ubuntu 12.04, Xfce Desktop, Thunderbird 14.0, Firefox 14.0.1.

Comment 12

5 years ago
howdy y'all,

this bug ...
- 775400 – external links sent to firefox cause firefox to steal focus
https://bugzilla.mozilla.org/show_bug.cgi?id=775400

... covers what may be the same thing. focus goes to some non-detectable-by-me thing instead of staying in the source app or going to the firefox window/tab.

should that one be duped to this one? as mlnease pointed out, the behavior has appeared in ff14.0.1. it did NOT occur in ff13. that makes _me_ think the two items are different.

take care,
lee

Comment 13

4 years ago
Same here.

After clicking a link in a Thunderbird message, TB looses focus to a hidden window of the class "FirefoxMessageWindow", width: 121px, height: 33px as reported by AHK Window Spy:

http://i.imgur.com/VjB88r2.png

In order to e.g. delete the current message in TB, after having clicked on a link in that message, first a second click in the message window is required in order to give back focus to TB.
Not shell integration so moving to general since I am unsure what component this should be in
Component: Shell Integration → General
You need to log in before you can comment on or make changes to this bug.