Skip to content

Commit ba16d25

Browse files
committed
Add ignore SSL errors options
Move some web browser client options to a new section called "Advanced"
1 parent e9c8f53 commit ba16d25

13 files changed

Lines changed: 152 additions & 34 deletions

File tree

src/Packages/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ public Resolution Resolution
114114
[Tooltip("Enable or disable incognito/private mode. When true, no profile-specific data is persisted to disk, but cache is still used to persist installation-specific data.")]
115115
public bool incognitoMode;
116116

117-
/// <summary>
118-
/// Enable or disable WebRTC
119-
/// </summary>
120-
[Tooltip("Enable or disable WebRTC")] public bool webRtc;
121-
122117
/// <summary>
123118
/// Enable or disable local storage
124119
/// </summary>
@@ -134,6 +129,12 @@ public Resolution Resolution
134129
/// Proxy Settings
135130
/// </summary>
136131
[Tooltip("Proxy settings")] public ProxySettings proxySettings;
132+
133+
/// <summary>
134+
/// Enable or disable WebRTC
135+
/// </summary>
136+
[Header("Advanced")]
137+
[Tooltip("Enable or disable WebRTC")] public bool webRtc;
137138

138139
/// <summary>
139140
/// Enable or disable remote debugging
@@ -159,6 +160,18 @@ public Resolution Resolution
159160
[Tooltip("Manager for JS methods")]
160161
public JsMethodManager jsMethodManager = new();
161162

163+
/// <summary>
164+
/// Will ignore SSL errors on provided domains in <see cref="ignoreSslErrorsDomains"/>
165+
/// </summary>
166+
[Tooltip("Will ignore SSL errors on provided domains in ignoreSSLErrorsDomains")]
167+
public bool ignoreSslErrors = false;
168+
169+
/// <summary>
170+
/// Domains to ignore SSL errors on if <see cref="ignoreSslErrors"/> is enabled
171+
/// </summary>
172+
[Tooltip("Domains to ignore SSL errors on if ignoreSSLErrors is enabled")]
173+
public string[] ignoreSslErrorsDomains;
174+
162175
/// <summary>
163176
/// The <see cref="CommunicationLayer" /> to use
164177
/// </summary>
@@ -385,6 +398,13 @@ internal void Init()
385398
if (!string.IsNullOrWhiteSpace(proxySettings.Password))
386399
argsBuilder.AppendArgument("proxy-password", proxySettings.Password, true);
387400
}
401+
402+
//Ignore ssl errors
403+
if (ignoreSslErrors)
404+
{
405+
argsBuilder.AppendArgument("ignore-ssl-errors", true);
406+
argsBuilder.AppendArgument("ignore-ssl-errors-domains", string.Join(",", ignoreSslErrorsDomains));
407+
}
388408

389409
//Make sure not to include this, its for testing
390410
#if UWB_ENGINE_PRJ //Define for backup, cause I am dumb as fuck and gonna accidentally include this in a release build one day

src/UnityWebBrowser.Engine.Cef/Main/Core/CefEngineControlsManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ public void Init(ClientControlsActions clientControlsActions, EnginePopupManager
222222
launchArguments.PopupAction,
223223
popupManager,
224224
new ProxySettings(launchArguments.ProxyUsername, launchArguments.ProxyPassword, launchArguments.ProxyEnabled),
225+
launchArguments.IgnoreSslErrors,
226+
launchArguments.IgnoreSslErrorsDomains,
225227
clientControlsActions,
226228
mainLogger,
227229
browserConsoleLogger);

src/UnityWebBrowser.Engine.Cef/Shared/Browser/Popups/UwbCefEnginePopupInfo.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,20 @@ public class UwbCefEnginePopupInfo : EnginePopupInfo
2424
/// </summary>
2525
/// <param name="proxySettings"></param>
2626
/// <param name="popupManager"></param>
27-
public UwbCefEnginePopupInfo(EnginePopupManager popupManager, ProxySettings proxySettings, ref CefClient client)
27+
/// <param name="client"></param>
28+
/// <param name="ignoreSslErrors"></param>
29+
/// <param name="ignoreSslErrorsDomains"></param>
30+
public UwbCefEnginePopupInfo(
31+
EnginePopupManager popupManager,
32+
ProxySettings proxySettings,
33+
ref CefClient client,
34+
bool ignoreSslErrors,
35+
string[] ignoreSslErrorsDomains)
2836
{
2937
this.popupManager = popupManager;
3038

3139
//Create a new client for it, and properly create the window
32-
popupClient = new UwbCefPopupClient(proxySettings, DisposeNoClose);
40+
popupClient = new UwbCefPopupClient(proxySettings, DisposeNoClose, ignoreSslErrors, ignoreSslErrorsDomains);
3341
client = popupClient;
3442
}
3543

src/UnityWebBrowser.Engine.Cef/Shared/Browser/Popups/UwbCefPopupClient.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ public class UwbCefPopupClient : CefClient
2222
/// </summary>
2323
/// <param name="proxySettings"></param>
2424
/// <param name="onShutdown"></param>
25-
public UwbCefPopupClient(ProxySettings proxySettings, Action onShutdown)
25+
/// <param name="ignoreSslErrors"></param>
26+
/// <param name="ignoreSslErrorsDomains"></param>
27+
public UwbCefPopupClient(
28+
ProxySettings proxySettings,
29+
Action onShutdown,
30+
bool ignoreSslErrors,
31+
string[] ignoreSslErrorsDomains)
2632
{
27-
requestHandler = new UwbCefRequestHandler(proxySettings);
33+
requestHandler = new UwbCefRequestHandler(proxySettings, ignoreSslErrors, ignoreSslErrorsDomains);
2834
lifeSpanHandler = new UwbCefPopupLifeSpanHandler(onShutdown);
2935
}
3036

src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefApp.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44
// This project is under the MIT license. See the LICENSE.md file for more details.
55

6+
#nullable enable
67
using VoltstroStudios.UnityWebBrowser.Engine.Shared.Core;
78
using Xilium.CefGlue;
89

@@ -16,9 +17,9 @@ public class UwbCefApp : CefApp
1617
private readonly bool mediaStreamingEnabled;
1718
private readonly bool noProxyServer;
1819
private readonly bool remoteDebugging;
19-
private readonly string[] remoteDebuggingOrigins;
20+
private readonly string[]? remoteDebuggingOrigins;
2021

21-
private UwbCefBrowserProcessHandler browserProcessHandler;
22+
private UwbCefBrowserProcessHandler browserProcessHandler = null!;
2223

2324
public UwbCefApp(LaunchArguments launchArguments)
2425
{
@@ -36,7 +37,7 @@ protected override void OnBeforeCommandLineProcessing(string processType, CefCom
3637
if (mediaStreamingEnabled && !commandLine.HasSwitch("--enable-media-stream"))
3738
commandLine.AppendSwitch("--enable-media-stream");
3839

39-
if (remoteDebugging && !commandLine.HasSwitch("--remote-allow-origins"))
40+
if (remoteDebugging && remoteDebuggingOrigins != null && !commandLine.HasSwitch("--remote-allow-origins"))
4041
commandLine.AppendSwitch("--remote-allow-origins", string.Join(',', remoteDebuggingOrigins));
4142

4243
#if LINUX || MACOS

src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefClient.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ internal class UwbCefClient : CefClient, IDisposable
4646
private UwbCefPopupClient devToolsClient;
4747

4848
//Dev Tools
49+
private readonly bool ignoreSslErrors;
50+
private readonly string[] ignoreSslErrorsDomains;
4951
private CefWindowInfo devToolsWindowInfo;
5052

5153
//State of mouse click events that needs to be persisted for dragging
@@ -59,6 +61,8 @@ public UwbCefClient(
5961
PopupAction popupAction,
6062
EnginePopupManager popupManager,
6163
ProxySettings proxySettings,
64+
bool ignoreSslErrors,
65+
string[] ignoreSslErrorsDomains,
6266
ClientControlsActions clientControlsActions,
6367
ILogger mainLogger,
6468
ILogger browserConsoleLogger)
@@ -72,16 +76,19 @@ public UwbCefClient(
7276
//Setup our handlers
7377
loadHandler = new UwbCefLoadHandler(this);
7478
renderHandler = new UwbCefRenderHandler(this, size);
75-
lifespanHandler = new UwbCefLifespanHandler(popupAction, popupManager, proxySettings);
79+
lifespanHandler = new UwbCefLifespanHandler(popupAction, popupManager, proxySettings, ignoreSslErrors, ignoreSslErrorsDomains);
7680
lifespanHandler.AfterCreated += cefBrowser =>
7781
{
7882
browser = cefBrowser;
7983
browserHost = cefBrowser.GetHost();
8084
};
8185
displayHandler = new UwbCefDisplayHandler(this, mainLogger, browserConsoleLogger);
82-
requestHandler = new UwbCefRequestHandler(proxySettings);
86+
requestHandler = new UwbCefRequestHandler(proxySettings, ignoreSslErrors, ignoreSslErrorsDomains);
8387
contextMenuHandler = new UwbCefContextMenuHandler();
8488

89+
this.ignoreSslErrors = ignoreSslErrors;
90+
this.ignoreSslErrorsDomains = ignoreSslErrorsDomains;
91+
8592
//Create message types
8693
messageTypes = new Dictionary<string, IMessageBase>
8794
{
@@ -306,7 +313,7 @@ public Vector2 GetMouseScrollPosition()
306313
/// Loads HTML content
307314
/// </summary>
308315
/// <param name="html"></param>
309-
public unsafe void LoadHtml(string html)
316+
public void LoadHtml(string html)
310317
{
311318
html = CefRuntime.Base64Encode(Encoding.UTF8.GetBytes(html));
312319
html = CefRuntime.UriEncode(html, false);
@@ -351,12 +358,15 @@ public void OpenDevTools()
351358
if (devToolsWindowInfo == null)
352359
{
353360
devToolsWindowInfo = CefWindowInfo.Create();
354-
devToolsClient = new UwbCefPopupClient(proxySettings, () =>
355-
{
356-
devToolsWindowInfo = null;
357-
devToolsClient = null;
358-
devToolsBrowserSettings = null;
359-
});
361+
devToolsClient = new UwbCefPopupClient(
362+
proxySettings, () =>
363+
{
364+
devToolsWindowInfo = null;
365+
devToolsClient = null;
366+
devToolsBrowserSettings = null;
367+
},
368+
ignoreSslErrors,
369+
ignoreSslErrorsDomains);
360370
devToolsBrowserSettings = new CefBrowserSettings();
361371
}
362372

src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefLifespanHandler.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ public class UwbCefLifespanHandler : CefLifeSpanHandler
2222

2323
private readonly EnginePopupManager popupManager;
2424
private readonly ProxySettings proxySettings;
25+
private readonly bool ignoreSslErrors;
26+
private readonly string[] ignoreSslErrorsDomains;
2527

26-
public UwbCefLifespanHandler(PopupAction popupAction, EnginePopupManager enginePopupManager,
27-
ProxySettings proxySettings)
28+
public UwbCefLifespanHandler(
29+
PopupAction popupAction,
30+
EnginePopupManager enginePopupManager,
31+
ProxySettings proxySettings,
32+
bool ignoreSslErrors,
33+
string[] ignoreSslErrorsDomains)
2834
{
2935
this.proxySettings = proxySettings;
3036
this.popupAction = popupAction;
3137
popupManager = enginePopupManager;
38+
this.ignoreSslErrors = ignoreSslErrors;
39+
this.ignoreSslErrorsDomains = ignoreSslErrorsDomains;
3240
}
3341

3442
public event Action<CefBrowser> AfterCreated;
@@ -52,7 +60,7 @@ protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string
5260
case PopupAction.Ignore:
5361
break;
5462
case PopupAction.OpenExternalWindow:
55-
popupManager.OnPopup(new UwbCefEnginePopupInfo(popupManager, proxySettings, ref client));
63+
popupManager.OnPopup(new UwbCefEnginePopupInfo(popupManager, proxySettings, ref client, ignoreSslErrors, ignoreSslErrorsDomains));
5664
return false;
5765
case PopupAction.Redirect:
5866
frame.LoadUrl(targetUrl);

src/UnityWebBrowser.Engine.Cef/Shared/Browser/UwbCefRequestHandler.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
//
44
// This project is under the MIT license. See the LICENSE.md file for more details.
55

6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using UnityWebBrowser.Engine.Cef.Core;
69
using VoltstroStudios.UnityWebBrowser.Shared;
710
using Xilium.CefGlue;
811

@@ -14,10 +17,14 @@ namespace UnityWebBrowser.Engine.Cef.Shared.Browser;
1417
public class UwbCefRequestHandler : CefRequestHandler
1518
{
1619
private readonly ProxySettings proxySettings;
20+
private readonly bool ignoreSslErrors;
21+
private readonly string[] ignoreSslErrorsDomains;
1722

18-
public UwbCefRequestHandler(ProxySettings proxySettings)
23+
public UwbCefRequestHandler(ProxySettings proxySettings, bool ignoreSslErrors, string[] ignoreSslErrorsDomains)
1924
{
2025
this.proxySettings = proxySettings;
26+
this.ignoreSslErrors = ignoreSslErrors;
27+
this.ignoreSslErrorsDomains = ignoreSslErrorsDomains;
2128
}
2229

2330
protected override CefResourceRequestHandler GetResourceRequestHandler(CefBrowser browser, CefFrame frame,
@@ -35,4 +42,22 @@ protected override bool GetAuthCredentials(CefBrowser browser, string originUrl,
3542

3643
return base.GetAuthCredentials(browser, originUrl, isProxy, host, port, realm, scheme, callback);
3744
}
45+
46+
protected override bool OnCertificateError(CefBrowser browser, CefErrorCode certError, string requestUrl, CefSslInfo sslInfo,
47+
CefCallback callback)
48+
{
49+
if (ignoreSslErrors && ignoreSslErrorsDomains != null)
50+
{
51+
requestUrl = requestUrl!.ToLower();
52+
bool contains = ignoreSslErrorsDomains.Any(x => requestUrl.Contains(x));
53+
if(contains)
54+
callback!.Continue();
55+
else
56+
callback!.Cancel();
57+
58+
return true;
59+
}
60+
61+
return false;
62+
}
3863
}

src/UnityWebBrowser.UnityProject/Packages/packages-lock.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,39 +167,39 @@
167167
"depth": 0,
168168
"source": "local",
169169
"dependencies": {
170-
"dev.voltstro.unitywebbrowser": "2.2.0"
170+
"dev.voltstro.unitywebbrowser": "2.2.1"
171171
}
172172
},
173173
"dev.voltstro.unitywebbrowser.engine.cef.linux.x64": {
174174
"version": "file:../../Packages/UnityWebBrowser.Engine.Cef.Linux-x64",
175175
"depth": 0,
176176
"source": "local",
177177
"dependencies": {
178-
"dev.voltstro.unitywebbrowser.engine.cef": "2.2.0-128.4.9"
178+
"dev.voltstro.unitywebbrowser.engine.cef": "2.2.1-129.0.11"
179179
}
180180
},
181181
"dev.voltstro.unitywebbrowser.engine.cef.macos.arm64": {
182182
"version": "file:../../Packages/UnityWebBrowser.Engine.Cef.MacOS-arm64",
183183
"depth": 0,
184184
"source": "local",
185185
"dependencies": {
186-
"dev.voltstro.unitywebbrowser.engine.cef": "2.2.0-128.4.9"
186+
"dev.voltstro.unitywebbrowser.engine.cef": "2.2.1-129.0.11"
187187
}
188188
},
189189
"dev.voltstro.unitywebbrowser.engine.cef.macos.x64": {
190190
"version": "file:../../Packages/UnityWebBrowser.Engine.Cef.MacOS-x64",
191191
"depth": 0,
192192
"source": "local",
193193
"dependencies": {
194-
"dev.voltstro.unitywebbrowser.engine.cef": "2.2.0-128.4.9"
194+
"dev.voltstro.unitywebbrowser.engine.cef": "2.2.1-129.0.11"
195195
}
196196
},
197197
"dev.voltstro.unitywebbrowser.engine.cef.win.x64": {
198198
"version": "file:../../Packages/UnityWebBrowser.Engine.Cef.Win-x64",
199199
"depth": 0,
200200
"source": "local",
201201
"dependencies": {
202-
"dev.voltstro.unitywebbrowser.engine.cef": "2.2.0-128.4.9"
202+
"dev.voltstro.unitywebbrowser.engine.cef": "2.2.1-129.0.11"
203203
}
204204
},
205205
"dev.voltstro.unitywebbrowser.unix-support": {

src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Core/EngineEntryPoint.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public int Main(string[] args)
8989
ClientControlsActions = new ClientControlsActions();
9090
PopupManager = new EnginePopupManager();
9191

92+
if(parsedArgs.IgnoreSslErrors && parsedArgs.IgnoreSslErrorsDomains != null)
93+
engineLogger.LogWarning("Ignore Ssl Errors is enabled! Proceed with caution on these domains: {Domains}", string.Join(", ", parsedArgs.IgnoreSslErrorsDomains));
94+
9295
EarlyInit(parsedArgs, args);
9396

9497
EntryPoint(parsedArgs, args);

0 commit comments

Comments
 (0)