MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / OnScriptWait

Method OnScriptWait

cpp/iedriver/IECommandExecutor.cpp:730–805  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

728}
729
730LRESULT IECommandExecutor::OnScriptWait(UINT uMsg,
731 WPARAM wParam,
732 LPARAM lParam,
733 BOOL& bHandled) {
734 LOG(TRACE) << "Entering IECommandExecutor::OnScriptWait";
735
736 BrowserHandle browser;
737 int status_code = this->GetCurrentBrowser(&browser);
738 if (status_code == WD_SUCCESS && !browser->is_closing()) {
739 if (this->async_script_timeout_ >= 0 && this->wait_timeout_ < clock()) {
740 ::SendMessage(browser->script_executor_handle(),
741 WD_ASYNC_SCRIPT_DETACH_LISTENTER,
742 NULL,
743 NULL);
744 Response timeout_response;
745 timeout_response.SetErrorResponse(ERROR_SCRIPT_TIMEOUT,
746 "Timed out waiting for script to complete.");
747 this->serialized_response_ = timeout_response.Serialize();
748 this->is_waiting_ = false;
749 browser->set_script_executor_handle(NULL);
750 } else {
751 HWND alert_handle;
752 bool is_execution_finished = ::SendMessage(browser->script_executor_handle(),
753 WD_ASYNC_SCRIPT_IS_EXECUTION_COMPLETE,
754 NULL,
755 NULL) != 0;
756 bool is_alert_active = this->IsAlertActive(browser, &alert_handle);
757 this->is_waiting_ = !is_execution_finished && !is_alert_active;
758 if (this->is_waiting_) {
759 // If we are still waiting, we need to wait a bit then post a message to
760 // ourselves to run the wait again. However, we can't wait using Sleep()
761 // on this thread. This call happens in a message loop, and we would be
762 // unable to process the COM events in the browser if we put this thread
763 // to sleep.
764 unsigned int thread_id = 0;
765 HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex(NULL,
766 0,
767 &IECommandExecutor::ScriptWaitThreadProc,
768 (void *)this->m_hWnd,
769 0,
770 &thread_id));
771 if (thread_handle != NULL) {
772 ::CloseHandle(thread_handle);
773 } else {
774 LOGERR(DEBUG) << "Unable to create waiter thread";
775 }
776 } else {
777 Response response;
778 Json::Value script_result;
779 ::SendMessage(browser->script_executor_handle(),
780 WD_ASYNC_SCRIPT_DETACH_LISTENTER,
781 NULL,
782 NULL);
783 int status_code = static_cast<int>(::SendMessage(browser->script_executor_handle(),
784 WD_ASYNC_SCRIPT_GET_RESULT,
785 NULL,
786 reinterpret_cast<LPARAM>(&script_result)));
787 if (status_code != WD_SUCCESS) {

Callers

nothing calls this directly

Calls 10

GetCurrentBrowserMethod · 0.95
IsAlertActiveMethod · 0.95
is_closingMethod · 0.80
SetErrorResponseMethod · 0.80
asStringMethod · 0.80
SetSuccessResponseMethod · 0.80
LOGClass · 0.50
SerializeMethod · 0.45

Tested by

no test coverage detected