Search code examples
c++winapicomiwebbrowser2

Disabling "Script Error" popup IWebBrowser2 c++ WinApi


Having a HWND with IWebBrowser2 on it. IWebBrowser2 is new CLSID_WEBBROWSER. When I navigating to youtube,google and etc, sometimes it shows me Script Error. And I want to disable it. How can I do it?


if (MoneyHWND == NULL) {
                if (SUCCEEDED(OleInitialize(NULL)))
                {
                    vector<wchar_t> fn(1000);
                    GetModuleFileName(0, fn.data(), 1000);
                    PathStripPath(fn.data());
                    RKEY k(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION");
                    k[fn.data()] = 11001UL; // Use IE 11
                    MoneyHWND = CreateDialog(GetModuleHandle(0), MAKEINTRESOURCE(IDD_FORMVIEW1), hWnd, MoneyProc);
                    pBrowser2 = new WebBrowser(MoneyHWND);

                    RECT rc;
                    GetClientRect(MoneyHWND, &rc);
                    pBrowser2->SetRect(rc);


                    pBrowser2->Navigate(site);

                    OleUninitialize();
                }
            }

Solution

  • IWebBrowser2::Silent:

    Sets or gets a value that indicates whether the object can display dialog boxes.

    Note, that the property is exposed to C and C++ programs using the following signatures:

    HRESULT IWebBrowser2::get_Silent(VARIANT_BOOL *pbSilent);
    HRESULT IWebBrowser2::put_Silent(VARIANT_BOOL bSilent);
    

    In other words:

        // ...
        auto hr{ pBrowser2->put_Silent(VARIANT_TRUE) };
        if FAILED(hr)
        {
            // Handle error
            // ...
        }