[Windows vst3 c++] Disable CORS on WebUI

I am looking for alternative ways of SAMFD.
My goal is sending a bit large array, or string data to WebUI.
I think sending byte array with for loop is the ultimate solution.
But there should be more efficient ways.
Web browser won’t let us load files from url other than http in script because of web security.
But launching browser with some options like “–disable-web-security” disable the protecction.
Then question, how can I do that for webview2?

Thanks.

seems like CoreWebView2HostResourceAccessKind.Allow needs to be specified somewhere

1 Like

Thanks for your replying, olilarkin!
Finally I found a solution by few hours researching.

  1. Open “IPlugWebView.cpp” that is in “iPlug2\IPlug\Extras\WebView”.

  2. Include “WebView2EnvironmentOptions.h
    #include "WebView2EnvironmentOptions.h"

  3. Replace
    PCWSTR additionalBrowserArguments,
    to
    ICoreWebView2EnvironmentOptions* environmentOptions,

typedef HRESULT(*TCCWebView2EnvWithOptions)(
    PCWSTR browserExecutableFolder,
    PCWSTR userDataFolder,
    ICoreWebView2EnvironmentOptions* environmentOptions, // <- This!!
    ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler* environment_created_handler);
  1. Look inside void* IWebView::OpenWebView.

Write some codes as follows:

    LPCWSTR arg = L" --disable-web-security";
    auto opt = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
    opt->put_AdditionalBrowserArguments(arg);

before if (handle != NULL).

  1. 3 or 4 lines below the code if (handle != NULL),
    You can see this code.
    HRESULT v = handle(nullptr, tmpPathWide, nullptr,
    Replace it to
    HRESULT v = handle(nullptr, tmpPathWide, opt.Get(),.

  2. Done.
    The result should be like this:

#include "IPlugWebView.h"
#include "IPlugPaths.h"
#include "WebView2EnvironmentOptions.h" // Step 2
#include <string>
#include <windows.h>
#include <cassert>

using namespace iplug;
using namespace Microsoft::WRL;

IWebView::IWebView(bool opaque)
{}

IWebView::~IWebView()
{
    CloseWebView();
}

typedef HRESULT(*TCCWebView2EnvWithOptions)(
    PCWSTR browserExecutableFolder,
    PCWSTR userDataFolder,
    ICoreWebView2EnvironmentOptions* environmentOptions, // Step 3
    ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler* environment_created_handler);

void* IWebView::OpenWebView(void* pParent, float x, float y, float w, float h, float scale)
{
    HWND hWnd = (HWND)pParent;

    x *= scale;
    y *= scale;
    w *= scale;
    h *= scale;

    assert(mDLLPath.GetLength() > 0);

    mDLLHandle = LoadLibraryA(mDLLPath.Get());

// Step 4 --------------------------------------------------------------
    LPCWSTR arg = L" --disable-web-security";
    auto opt = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
    opt->put_AdditionalBrowserArguments(arg);
// -------------------------------------------------------------- Step 4

    TCCWebView2EnvWithOptions handle = (TCCWebView2EnvWithOptions)GetProcAddress(mDLLHandle, "CreateCoreWebView2EnvironmentWithOptions");

    if (handle != NULL)
    {
        WCHAR tmpPathWide[IPLUG_WIN_MAX_WIDE_PATH];
        UTF8ToUTF16(tmpPathWide, mTmpPath.Get(), IPLUG_WIN_MAX_WIDE_PATH);
        HRESULT  v = handle(nullptr, tmpPathWide, opt.Get(), // Step 5