Open Bug 1769454 Opened 3 years ago Updated 3 years ago

When Firefox is currently the window with keyboard focus and ShellExecute is ran with a URL, Firefox loses focus.

Categories

(Core :: Widget: Win32, defect, P5)

Firefox 100
defect

Tracking

()

UNCONFIRMED

People

(Reporter: gsalin97+1, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0

Steps to reproduce:

I can reproduce by following these steps:

  1. Set Firefox as the default web browser on Windows 11
  2. Write a program that uses ShellExecute to open a URL in the default web browser and contains a delay to make the program sleep for X seconds
  3. Run program
  4. Switch to Firefox (Firefox should have keyboard focus)
  5. Firefox loses focus after the delay and after the ShellExecute opens a new tab

Actual results:

Actual results: A new tab is correctly opened but the Firefox window loses keyboard focus.

Expected results:

Expected results: Firefox should not lose focus.

This can probably be reproduced in any programming language where you can open URLs in the default web browser since I'm convinced that they all use the same underlying mechanism on Windows: the ShellExecute function that belongs to the Win32 API.

Here are some code samples that all reproduce this bug in C++ and Python. In all of these examples, we sleep the calling thread so that you have time to switch to Firefox.

C++14:

#include <chrono>
#include <thread>
#include <Windows.h>

int main()
{
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
ShellExecute(NULL, L"open", L"https://example.com", NULL, NULL, SW_SHOW);
}


Python 3.10.0:

import time
import webbrowser

def main():
time.sleep(2.5)
url = "https://example.com"
webbrowser.open(url)

if name == "main":
main()


For what it's worth, this issue does not occur when Microsoft Edge or Google Chrome are the default web browser which leads me to believe that this is specific to Firefox.

The Bugbug bot thinks this bug should belong to the 'Core::Widget: Win32' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Widget: Win32
Product: Firefox → Core

Does changing SW_SHOW to SW_SHOWNORMAL make a difference?

Severity: -- → S4
Flags: needinfo?(gsalin97+1)
Priority: -- → P5

(In reply to Stephen A Pohl [:spohl] from comment #2)

Does changing SW_SHOW to SW_SHOWNORMAL make a difference?

Unfortunately, it doesn't. The Firefox window still deactivates.

Flags: needinfo?(gsalin97+1)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: