Skip to content

Commit 6e85abb

Browse files
authored
[IEDriver] Ignore process id match when finding the window handle - IE Mode on Edge. (#12246)
This assumes a single Edge instance is running on the host. Not suited for running sessions in parallel, or having another Edge browser manually at the same time, because it will most likely lead to return the wrong window handle.
1 parent b49da80 commit 6e85abb

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

cpp/iedriver/BrowserFactory.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ BrowserFactory::BrowserFactory(void) {
101101
this->GetIEVersion();
102102
this->oleacc_instance_handle_ = NULL;
103103
this->edge_ie_mode_ = false;
104+
this->ignore_process_match_ = false;
104105
}
105106

106107
BrowserFactory::~BrowserFactory(void) {
@@ -127,6 +128,7 @@ void BrowserFactory::Initialize(BrowserFactorySettings settings) {
127128
this->browser_command_line_switches_ = StringUtilities::ToWString(settings.browser_command_line_switches);
128129
this->initial_browser_url_ = StringUtilities::ToWString(settings.initial_browser_url);
129130
this->edge_ie_mode_ = settings.attach_to_edge_ie || this->ie_redirects_edge_;
131+
this->ignore_process_match_ = settings.ignore_process_match;
130132
this->ignore_zoom_setting_ = settings.ignore_zoom_setting || this->edge_ie_mode_;
131133
LOG(DEBUG) << "path before was " << settings.edge_executable_path << "\n";
132134
this->edge_executable_location_ = StringUtilities::ToWString(settings.edge_executable_path);
@@ -565,8 +567,18 @@ bool BrowserFactory::AttachToBrowserUsingActiveAccessibility
565567
reinterpret_cast<LPARAM>(process_window_info));
566568
} else {
567569
// If we're in edge_ie_mode, we need to look for different windows
568-
::EnumWindows(&BrowserFactory::FindEdgeWindow,
570+
if (this->ignore_process_match_) {
571+
LOG(TRACE) << "Finding windonw handle for IE Mode on Edge, "
572+
<< "ignoring process id match. This assumes only one "
573+
<< "Edge instance is running on the host.";
574+
::EnumWindows(&BrowserFactory::FindEdgeWindowIgnoringProcessMatch,
575+
reinterpret_cast<LPARAM>(process_window_info));
576+
} else {
577+
LOG(TRACE) << "Finding windonw handle for IE Mode on Edge";
578+
::EnumWindows(&BrowserFactory::FindEdgeWindow,
569579
reinterpret_cast<LPARAM>(process_window_info));
580+
581+
}
570582
}
571583

572584
if (process_window_info->hwndBrowser == NULL) {
@@ -1116,6 +1128,21 @@ BOOL CALLBACK BrowserFactory::FindEdgeWindow(HWND hwnd, LPARAM arg) {
11161128
return EnumChildWindows(hwnd, FindEdgeChildWindowForProcess, arg);
11171129
}
11181130

1131+
BOOL CALLBACK BrowserFactory::FindEdgeWindowIgnoringProcessMatch(HWND hwnd, LPARAM arg) {
1132+
// Could this be an EdgeChrome window?
1133+
// 19 == "Chrome_WidgetWin_1"
1134+
char name[20];
1135+
if (::GetClassNameA(hwnd, name, 20) == 0) {
1136+
// No match found. Skip
1137+
return TRUE;
1138+
}
1139+
1140+
// continue if it is not "Chrome_WidgetWin_1"
1141+
if (strcmp(ANDIE_FRAME_WINDOW_CLASS, name) != 0) return TRUE;
1142+
1143+
return EnumChildWindows(hwnd, FindEdgeChildWindowForProcess, arg);
1144+
}
1145+
11191146
BOOL CALLBACK BrowserFactory::FindIEBrowserHandles(HWND hwnd, LPARAM arg) {
11201147
std::vector<HWND>* handles = reinterpret_cast<std::vector<HWND>*>(arg);
11211148

cpp/iedriver/BrowserFactory.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct BrowserFactorySettings {
3838
std::string browser_command_line_switches;
3939
bool attach_to_edge_ie; // Used to attach to EdgeChromium IE processes
4040
std::string edge_executable_path;
41+
bool ignore_process_match; // Ignores window handle process id match on IE Mode.
4142
};
4243

4344
class BrowserFactory {
@@ -62,6 +63,7 @@ class BrowserFactory {
6263
bool force_createprocess_api(void) const { return this->force_createprocess_api_; }
6364
bool force_shell_windows_api(void) const { return this->force_shell_windows_api_; }
6465
int browser_attach_timeout(void) const { return this->browser_attach_timeout_; }
66+
bool ignore_process_match(void) const { return this->ignore_process_match_; }
6567
std::string initial_browser_url(void);
6668
std::string browser_command_line_switches(void);
6769

@@ -81,6 +83,7 @@ class BrowserFactory {
8183
private:
8284
static BOOL CALLBACK FindBrowserWindow(HWND hwnd, LPARAM param);
8385
static BOOL CALLBACK FindEdgeWindow(HWND hwnd, LPARAM param);
86+
static BOOL CALLBACK FindEdgeWindowIgnoringProcessMatch(HWND hwnd, LPARAM param);
8487
static bool IsWindowsVersionOrGreater(unsigned short major_version,
8588
unsigned short minor_version,
8689
unsigned short service_pack);
@@ -136,6 +139,7 @@ class BrowserFactory {
136139
bool ie_redirects_edge_;
137140

138141
bool edge_ie_mode_;
142+
bool ignore_process_match_;
139143
std::wstring edge_executable_location_;
140144
std::wstring edge_user_data_dir_;
141145
};

cpp/iedriver/CommandHandlers/NewSessionCommandHandler.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,16 @@ void NewSessionCommandHandler::SetBrowserFactorySettings(const IECommandExecutor
420420
false);
421421
factory_settings.attach_to_edge_ie = attach_to_edgechrome.asBool();
422422

423+
// Ignore window handle process id match when launching Edge on IE Mode
424+
// Useful when the process is launched with admin/privilege rights. This
425+
// assumes only one Edge browser is running on the host.
426+
factory_settings.ignore_process_match = false;
427+
Json::Value ignore_process_match_ie_mode = this->GetCapability(capabilities,
428+
IGNORE_PROCESS_MATCH,
429+
Json::booleanValue,
430+
false);
431+
factory_settings.ignore_process_match = ignore_process_match_ie_mode.asBool();
432+
423433
Json::Value edge_executable_path = this->GetCapability(capabilities,
424434
EDGE_EXECUTABLE_PATH,
425435
Json::stringValue,
@@ -564,6 +574,7 @@ Json::Value NewSessionCommandHandler::CreateReturnedCapabilities(const IECommand
564574
ie_options[BROWSER_COMMAND_LINE_SWITCHES_CAPABILITY] = executor.browser_factory()->browser_command_line_switches();
565575
ie_options[FORCE_CREATE_PROCESS_API_CAPABILITY] = executor.browser_factory()->force_createprocess_api();
566576
ie_options[ENSURE_CLEAN_SESSION_CAPABILITY] = executor.browser_factory()->clear_cache();
577+
ie_options[IGNORE_PROCESS_MATCH] = executor.browser_factory()->ignore_process_match();
567578
ie_options[NATIVE_EVENTS_CAPABILITY] = executor.input_manager()->enable_native_events();
568579
ie_options[ENABLE_PERSISTENT_HOVER_CAPABILITY] = executor.input_manager()->use_persistent_hover();
569580
ie_options[ELEMENT_SCROLL_BEHAVIOR_CAPABILITY] = executor.input_manager()->scroll_behavior();

cpp/iedriver/WebDriverConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#define ENABLE_FULL_PAGE_SCREENSHOT_CAPABILITY "ie.enableFullPageScreenshot"
6767
#define ATTACH_TO_EDGE_CHROME "ie.edgechromium"
6868
#define EDGE_EXECUTABLE_PATH "ie.edgepath"
69+
#define IGNORE_PROCESS_MATCH "ie.ignoreprocessmatch"
6970

7071
// New top-level browsing context types
7172
#define WINDOW_WINDOW_TYPE "window"

0 commit comments

Comments
 (0)