As promised the solution I got at the end:
The javascript calls a webpage that doesn't exist. The Request & Resource Handler catch this call and return their own anwser. When you implement your own Request/Resource handler, you have to replace the NotImplementedException in some cases even if you don't need the functionality. Just visit the offical documentation for the default behaviour in this case: http://cefsharp.github.io/api/75.1.x/html/T_CefSharp_IRequestHandler.htm
XAML:
<Window x:Class="Chromium.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
...
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<cefSharp:ChromiumWebBrowser
x:Name="ChromiumWebBrowser"
/>
</Grid>
</Window>
MainWindow.Xaml.cs
public MainWindow()
{
InitializeComponent();
ChromiumWebBrowser.BrowserSettings.WebSecurity = CefState.Disabled;
ChromiumWebBrowser.RequestHandler = new RequestHandler();
ChromiumWebBrowser.Address = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestHtml", "index.html");
}
index.html
<!doctype html>
<html>
<head>
<link href="css/style.css" rel="stylesheet" type="text/css">
<script src="js/script.js" type="text/javascript"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<h1>Title</h1>
<p id="result"></p>
<button onclick="call()">Call</button>
</body>
JS Script
function call() {
axios.get('http://doesnt_exist')
.then((response) => {
console.log(response);
document.getElementById("result").innerHTML = JSON.stringify(response.data);
});
}
Request Handler
public class RequestHandler : IRequestHandler
{
public IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
{
Console.WriteLine("GetResourceRequestHandler " + request.Url);
return new ResourceRequestHandler();
}
...
}
ResourceRequestHandler
class ResourceRequestHandler : IResourceRequestHandler
{
public IResourceHandler GetResourceHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request)
{
Console.WriteLine("GetResourceHandler " + request.Url);
if (request.Url.Contains("doesnt_exist"))
return ResourceHandler.FromString("Hello");
return null;
}
...
}