ERROR:crashpad_client_win.cc(867)] not connected - Electron js

208 Views Asked by At

Basically I'm calling a c++ function through addon into my Electron js javascript code. I have to use this function in a interval every 1 second. The function works fine however sometimes the app crashes with this message.

ERROR:crashpad_client_win.cc(867)] not connected

i am calling function like this,

const addon = require("addon.node");

addon.getOperaURL()

please suggest me solution to get rid of this crash completely.

I don't know if it is related but to facilitate further here is my c++ function

std::wstring getOperaURL(HWND windowHandle) {
    // Checking if the address bar for the given window handle is already cached
    for (const auto& cachedAddressBar : cachedAddressBars) {
        if (IsWindow(cachedAddressBar.windowHandle) && IsWindow(windowHandle) &&
            (cachedAddressBar.windowHandle == windowHandle)) {
            std::wstring cachedUrl = retrieveUrlFromAddressBar(cachedAddressBar.addressBarElement);
            return cachedUrl;
        }
    }

    HRESULT hr = CoInitialize(nullptr);
    if (FAILED(hr)) {
        return L"Error initializing COM";
    }

    // Initialize pointers to nullptr for proper resource management
    IUIAutomation* automation = nullptr;
    IUIAutomationElement* desktop = nullptr;
    IUIAutomationElement* operaWindow = nullptr;
    IUIAutomationElement* addressBar = nullptr;
    IUIAutomationCondition* addressBarCondition = nullptr;
    IUIAutomationCondition* editControlCondition = nullptr;
    IUIAutomationCondition* titleCondition = nullptr;

    do {
        // Create UI Automation instance
        hr = CoCreateInstance(CLSID_CUIAutomation, nullptr, CLSCTX_INPROC_SERVER, IID_IUIAutomation, (void**)&automation);
        if (FAILED(hr)) {
            break;
        }

        // Get the desktop element
        hr = automation->GetRootElement(&desktop);
        if (FAILED(hr)) {
            break;
        }

        // Find the Opera window using "Pane" as the control type
        hr = automation->CreatePropertyCondition(UIA_NativeWindowHandlePropertyId, CComVariant(reinterpret_cast<LONG>(windowHandle)), &addressBarCondition);
        if (FAILED(hr)) {
            break;
        }

        hr = desktop->FindFirst(TreeScope_Descendants, addressBarCondition, &operaWindow);
        if (FAILED(hr)) {
            break;
        }

        // Find the address bar using "Edit" as the control type
        hr = automation->CreatePropertyCondition(UIA_NamePropertyId, CComVariant(L"Address field"), &titleCondition);
        if (FAILED(hr)) {
            break;
        }
        hr = automation->CreatePropertyCondition(UIA_ControlTypePropertyId, CComVariant(UIA_EditControlTypeId), &editControlCondition);
        if (FAILED(hr)) {
            break;
        }
        hr = automation->CreateAndCondition(titleCondition, editControlCondition, &addressBarCondition);
        if (FAILED(hr)) {
            break;
        }
        // Find the address bar using the combined condition
        hr = operaWindow->FindFirst(TreeScope_Subtree, addressBarCondition, &addressBar);
        if (FAILED(hr)) {
            break;
        }
        // Cache the address bar element along with the window handle
        // cachedAddressBars.emplace_back(addressBar, windowHandle);

        // Retrieve and return the URL
        VARIANT addressBarValue;
        hr = addressBar->GetCurrentPropertyValue(UIA_ValueValuePropertyId, &addressBarValue);
        if (FAILED(hr)) {
            break;
        }

        // Convert VARIANT to wstring
        std::wstring url(addressBarValue.bstrVal);
        VariantClear(&addressBarValue);

        return url;

    } while (false);

    // Cleanup resources in case of an error
    if (addressBarCondition) addressBarCondition->Release();
    if (editControlCondition) editControlCondition->Release();
    if (titleCondition) titleCondition->Release();
    if (addressBar) addressBar->Release();
    if (operaWindow) operaWindow->Release();
    if (desktop) desktop->Release();
    if (automation) automation->Release();

    CoUninitialize();
    return L"Error in UI Automation";
}
0

There are 0 best solutions below