Skip to content

Commit 3b8804a

Browse files
committed
Add additionalBrowserArguments config option
1 parent 1075af5 commit 3b8804a

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/Config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ConfigJson LoadConfigJson(const std::string& path)
1111
ConfigJson ret;
1212
ret.startUrl = "https://github.com/WebView-CG/CanIWebView2";
1313
ret.preferUnstableChannel = false;
14+
ret.additionalBrowserArguments = "";
1415

1516
// If file does not exist, just use defaults
1617
if (!FileExists(path))
@@ -35,5 +36,8 @@ ConfigJson LoadConfigJson(const std::string& path)
3536
if (parsedJson.contains("preferUnstableChannel"))
3637
ret.preferUnstableChannel = parsedJson["preferUnstableChannel"].get<bool>();
3738

39+
if (parsedJson.contains("additionalBrowserArguments"))
40+
ret.additionalBrowserArguments = parsedJson["additionalBrowserArguments"].get<std::string>();
41+
3842
return ret;
3943
}

src/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
struct ConfigJson {
66
std::string startUrl;
77
bool preferUnstableChannel;
8+
std::string additionalBrowserArguments;
89
};
910

1011
ConfigJson LoadConfigJson(const std::string& path);

src/WebView.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,18 @@ int CALLBACK WinMain(
9292
// The default channel search order is the WebView2 Runtime, Beta, Dev, and Canary (i.e. stable to unstable).
9393
// When preferUnstableCannel is true in config.json, set the ChannelSearchKind option to
9494
// to COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE which reverses the channel search order.
95+
// See: https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel
9596
if (configJson.preferUnstableChannel)
9697
{
9798
options->put_ChannelSearchKind(COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE);
9899
}
99100

101+
// Specify additional browser arguments if non-empty string provided
102+
if (!configJson.additionalBrowserArguments.empty())
103+
{
104+
options->put_AdditionalBrowserArguments(Utf8ToWide(configJson.additionalBrowserArguments).c_str());
105+
}
106+
100107
CreateCoreWebView2EnvironmentWithOptions(nullptr, nullptr, options.Get(),
101108
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(
102109
[hWnd, configJson](HRESULT result, ICoreWebView2Environment* env) -> HRESULT {

0 commit comments

Comments
 (0)