MicrosoftEdge / WebView2Browser

A web browser built with the Microsoft Edge WebView2 control.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Removing some things (Dev tools and Save as menu)

opened this issue · comments

As the title suggests how would I go about removing the dev tools and save as menu?

Yes it seems like you can, @tobyg0.
After seeing something in BrowserWindow.cpp about this I checked Microsoft's documentation for WebView2 and came across ICoreWebView2Settings which is used to "enable, disable, or modify WebView features".

The members you're looking for are put_AreDefaultContextMenusEnabled and put_AreDevToolsEnabled.

Context menus:

/* Snippet from ICoreWebView2Settings documentation */

BOOL allowContextMenus;
CHECK_FAILURE(m_settings->get_AreDefaultContextMenusEnabled(&allowContextMenus));
if (allowContextMenus)
{
    CHECK_FAILURE(m_settings->put_AreDefaultContextMenusEnabled(FALSE));
    MessageBox(
        nullptr, L"Context menus will be disabled after the next navigation.",
        L"Settings change", MB_OK);
}
else
{
    CHECK_FAILURE(m_settings->put_AreDefaultContextMenusEnabled(TRUE));
    MessageBox(
        nullptr, L"Context menus will be enabled after the next navigation.",
        L"Settings change", MB_OK);
}

Developer Tools:

/* Snippet from made up b/c there wasn't one in the documentation */

BOOL allowDevTools;
CHECK_FAILURE(m_settings->get_AreDevToolsEnabled(&allowDevTools));
if (allowDevTools)
{
    CHECK_FAILURE(m_settings->put_AreDevToolsEnabled(FALSE));
    MessageBox(
        nullptr, L"Dev tools will be disabled after the next navigation.",
        L"Settings change", MB_OK);
}
else
{
    CHECK_FAILURE(m_settings->put_AreDevToolsEnabled(TRUE));
    MessageBox(
        nullptr, L"Dev tools will be enabled after the next navigation.",
        L"Settings change", MB_OK);
}

(I know very little c++, so don't hurt me, but I had this same question but for the WebView2 WinForms Control- which I then noticed this was not. But I decide to look around anyways and see if I could find and post an answer here for others that stumble upon this- hope it helps)