SEBWIN-328: Implemented static user agent to fix issue with as of yet unsupported request interception for requests made by service workers.
This commit is contained in:
parent
2fd4bfa78a
commit
e46316a69d
7 changed files with 30 additions and 7 deletions
|
@ -129,7 +129,7 @@ namespace SafeExamBrowser.Browser
|
|||
CachePath = appConfig.BrowserCachePath,
|
||||
LogFile = appConfig.BrowserLogFile,
|
||||
LogSeverity = error ? LogSeverity.Error : (warning ? LogSeverity.Warning : LogSeverity.Info),
|
||||
UserAgent = settings.UseCustomUserAgent ? settings.CustomUserAgent : string.Empty
|
||||
UserAgent = InitializeUserAgent()
|
||||
};
|
||||
|
||||
cefSettings.CefCommandLineArgs.Add("touch-events", "enabled");
|
||||
|
@ -165,5 +165,24 @@ namespace SafeExamBrowser.Browser
|
|||
instances.Remove(instances.FirstOrDefault(i => i.Id == id));
|
||||
logger.Info($"Browser instance {id} was terminated.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TODO: Workaround to correctly set the user agent due to missing support for request interception for requests made by service workers.
|
||||
/// Remove once CEF fully supports service workers and reactivate the functionality in <see cref="Handlers.RequestHandler"/>!
|
||||
/// </summary>
|
||||
private string InitializeUserAgent()
|
||||
{
|
||||
var osVersion = $"{Environment.OSVersion.Version.Major}.{Environment.OSVersion.Version.Minor}";
|
||||
var sebVersion = $"SEB/{appConfig.ProgramVersion}";
|
||||
|
||||
if (settings.UseCustomUserAgent)
|
||||
{
|
||||
return $"{settings.CustomUserAgent} {sebVersion}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"Mozilla/5.0 (Windows NT {osVersion}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{Cef.ChromiumVersion} {sebVersion}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ using BrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.Browser
|
|||
namespace SafeExamBrowser.Browser.Handlers
|
||||
{
|
||||
/// <remarks>
|
||||
/// See https://cefsharp.github.io/api/71.0.0/html/T_CefSharp_IContextMenuHandler.htm.
|
||||
/// See https://cefsharp.github.io/api/73.1.x/html/T_CefSharp_IContextMenuHandler.htm.
|
||||
/// </remarks>
|
||||
internal class ContextMenuHandler : IContextMenuHandler
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ using SafeExamBrowser.Browser.Events;
|
|||
namespace SafeExamBrowser.Browser.Handlers
|
||||
{
|
||||
/// <remarks>
|
||||
/// See https://cefsharp.github.io/api/71.0.0/html/T_CefSharp_IDisplayHandler.htm.
|
||||
/// See https://cefsharp.github.io/api/73.1.x/html/T_CefSharp_IDisplayHandler.htm.
|
||||
/// </remarks>
|
||||
internal class DisplayHandler : IDisplayHandler
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ using BrowserSettings = SafeExamBrowser.Contracts.Configuration.Settings.Browser
|
|||
namespace SafeExamBrowser.Browser.Handlers
|
||||
{
|
||||
/// <remarks>
|
||||
/// See https://cefsharp.github.io/api/71.0.0/html/T_CefSharp_IDownloadHandler.htm.
|
||||
/// See https://cefsharp.github.io/api/73.1.x/html/T_CefSharp_IDownloadHandler.htm.
|
||||
/// </remarks>
|
||||
internal class DownloadHandler : IDownloadHandler
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ using SafeExamBrowser.Contracts.UserInterface;
|
|||
namespace SafeExamBrowser.Browser.Handlers
|
||||
{
|
||||
/// <remarks>
|
||||
/// See https://cefsharp.github.io/api/71.0.0/html/T_CefSharp_IKeyboardHandler.htm.
|
||||
/// See https://cefsharp.github.io/api/73.1.x/html/T_CefSharp_IKeyboardHandler.htm.
|
||||
/// </remarks>
|
||||
internal class KeyboardHandler : IKeyboardHandler
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ using SafeExamBrowser.Browser.Events;
|
|||
namespace SafeExamBrowser.Browser.Handlers
|
||||
{
|
||||
/// <remarks>
|
||||
/// See https://cefsharp.github.io/api/71.0.0/html/T_CefSharp_ILifeSpanHandler.htm.
|
||||
/// See https://cefsharp.github.io/api/73.1.x/html/T_CefSharp_ILifeSpanHandler.htm.
|
||||
/// </remarks>
|
||||
internal class LifeSpanHandler : ILifeSpanHandler
|
||||
{
|
||||
|
|
|
@ -28,7 +28,11 @@ namespace SafeExamBrowser.Browser.Handlers
|
|||
|
||||
public override CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
|
||||
{
|
||||
AppendCustomUserAgent(request);
|
||||
// TODO: CEF does not yet support intercepting requests from service workers, thus the user agent must be statically set at browser
|
||||
// startup for now. Once CEF has full support of service workers, the static user agent should be removed and the method below
|
||||
// reactivated. See https://bitbucket.org/chromiumembedded/cef/issues/2622 for the current status of development.
|
||||
// AppendCustomUserAgent(request);
|
||||
|
||||
ReplaceCustomScheme(request);
|
||||
|
||||
return base.OnBeforeResourceLoad(browserControl, browser, frame, request, callback);
|
||||
|
|
Loading…
Reference in a new issue