Skip to content

Commit 74a7ba5

Browse files
committed
Handling very rare race condition in IE driver with multiple windows
1 parent 9ae8bdb commit 74a7ba5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

cpp/iedriver/IECommandExecutor.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,23 @@ LRESULT IECommandExecutor::OnBrowserQuit(UINT uMsg,
297297
delete[] str;
298298
BrowserMap::iterator found_iterator = this->managed_browsers_.find(browser_id);
299299
if (found_iterator != this->managed_browsers_.end()) {
300-
this->managed_browsers_.erase(browser_id);
301-
if (this->managed_browsers_.size() == 0) {
302-
this->current_browser_id_ = "";
300+
// If there's still an alert window active, repost this message to
301+
// ourselves, since the alert will be handled either automatically or
302+
// manually by the user.
303+
HWND alert_handle;
304+
if (this->IsAlertActive(found_iterator->second, &alert_handle)) {
305+
LOG(DEBUG) << "Alert is active on closing browser window. Reposting message.";
306+
LPSTR message_payload = new CHAR[browser_id.size() + 1];
307+
strcpy_s(message_payload, browser_id.size() + 1, browser_id.c_str());
308+
::PostMessage(this->m_hWnd,
309+
WD_BROWSER_QUIT,
310+
NULL,
311+
reinterpret_cast<LPARAM>(message_payload));
312+
} else {
313+
this->managed_browsers_.erase(browser_id);
314+
if (this->managed_browsers_.size() == 0) {
315+
this->current_browser_id_ = "";
316+
}
303317
}
304318
} else {
305319
LOG(WARN) << "Unable to find browser to quit with ID " << browser_id;

0 commit comments

Comments
 (0)