Skip to content

Commit be14751

Browse files
authored
Merge pull request #9 from pandrr/feature/allow-insecure-sockets
Add config option to allow running insecure content
2 parents d25e9db + 5c3fc7f commit be14751

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎MainWindow.xaml.cs‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ CoreWebView2Environment WebViewEnvironment
4646

4747
bool _propagateKeys = false;
4848

49+
HashSet<string> _additionalBrowserArguments = new HashSet<string>(StringComparer.Ordinal);
50+
51+
private void AddBrowserArgument(string argument)
52+
{
53+
if (string.IsNullOrWhiteSpace(argument))
54+
{
55+
return;
56+
}
57+
58+
_additionalBrowserArguments.Add(argument.Trim());
59+
}
60+
61+
private void SetAdditionalBrowserArguments()
62+
{
63+
if (_additionalBrowserArguments.Count == 0)
64+
{
65+
return;
66+
}
67+
68+
Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", string.Join(" ", _additionalBrowserArguments));
69+
}
70+
4971
public MainWindow()
5072
{
5173
var dlg = new DemoDialog();
@@ -58,6 +80,7 @@ public MainWindow()
5880
var currentTag = "";
5981
var dialogTitle = "webDemoExe";
6082
var autostart = false;
83+
var allowRunningInsecureContent = false;
6184

6285
try
6386
{
@@ -73,6 +96,7 @@ public MainWindow()
7396
{
7497
if (currentTag.Equals("autostart")) autostart = true;
7598
if (currentTag.Equals("propagatekeys")) _propagateKeys = true;
99+
if (currentTag.Equals("allowrunninginsecurecontent")) allowRunningInsecureContent = true;
76100
}
77101
break;
78102

@@ -81,6 +105,7 @@ public MainWindow()
81105
if (currentTag.Equals("domain")) _appDomain = reader.Value;
82106
if (currentTag.Equals("autostart")) autostart = XmlConvert.ToBoolean(reader.Value);
83107
if (currentTag.Equals("propagatekeys")) _propagateKeys = XmlConvert.ToBoolean(reader.Value);
108+
if (currentTag.Equals("allowrunninginsecurecontent")) allowRunningInsecureContent = XmlConvert.ToBoolean(reader.Value);
84109
break;
85110
}
86111
}
@@ -91,9 +116,12 @@ public MainWindow()
91116
dialogTitle = "xml error";
92117

93118
MessageBox.Show($"Could not parse {configFile}: {dialogTitle}: {e.Message}");
94-
}
119+
}
95120

96-
121+
if (allowRunningInsecureContent)
122+
{
123+
AddBrowserArgument("--allow-running-insecure-content");
124+
}
97125

98126
if (autostart==false)
99127
{
@@ -102,7 +130,7 @@ public MainWindow()
102130
dlg.ShowDialog();
103131

104132

105-
Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--autoplay-policy=no-user-gesture-required");
133+
AddBrowserArgument("--autoplay-policy=no-user-gesture-required");
106134
Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", Path.GetTempPath());
107135

108136
if (dlg.DialogResult == true)
@@ -115,6 +143,8 @@ public MainWindow()
115143
}
116144
}
117145

146+
SetAdditionalBrowserArguments();
147+
118148
DataContext = this;
119149
InitializeComponent();
120150
AttachControlEventHandlers(webView);

‎readme.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ wrap your web demo into a windows exe format, just like a native demo.
2222
- rename webdemoexe.exe to your demo name
2323
- add `<autostart/>` into the config to not show the dialog at all and start directly, don't do this if you want to play audio without having another user interaction!
2424
- add `<domain>yourdomain.localhost</domain>` to customize the virtual host domain (defaults to webdemoexe.localhost)
25+
- add `<allowrunninginsecurecontent/>` to allow insecure content (for example `ws://` for unencrypted websocket connections)
2526

2627
- if the url contains "webdemoexe_exit" it will exit, e.g. use window.location.hash="webdemoexe_exit"
2728

@@ -30,6 +31,7 @@ wrap your web demo into a windows exe format, just like a native demo.
3031
- webdemoexe uses [webview2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/) and creates a virtual host from the demo subfolder to run your demo
3132
- escape to close is handled by webdemoexe
3233
- if you need to handle escape key manually, add `<propagatekeys/>` in the config.
34+
- if insecure connections are needed, set `<allowrunninginsecurecontent/>` (equivalent to [WebView flag](https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/webview-features-flags?tabs=dotnetcsharp) `allow-running-insecure-content`)
3335
- no gesture is needed to auto play audio, if you normally display a play button, make sure it only shows when audiocontext stats is not "running"...
3436

3537
### ideas

0 commit comments

Comments
 (0)