btoa() and atob() are not working
RyuzakiH opened this issue · comments
Description
btoa() and atob() methods are not working despite they're declared here WindowBase64.cs
Steps to Reproduce
- Create a console application (.NET Framework 4.6.2)
- Run this code (from AngleSharp.Samples)
// We require a custom configuration with JavaScript
var config = Configuration.Default.WithJs();
// This is our sample source, we will set the title and write on the document
var source = @"<!doctype html>
<html>
<head><title>Sample</title></head>
<body>
<script>
document.title = 'Simple manipulation...';
//document.write('<span class=greeting>Hello World!</span>');
document.write(btoa('test'));
</script>
</body>";
var document = BrowsingContext.New(config).OpenAsync(m => m.Content(source)).Result;
// Modified HTML will be output
Console.WriteLine(document.DocumentElement.OuterHtml);
Expected behavior:
Oputput: (in browser)
<html><head><title>Simple manipulation...</title></head>
<body>
<script>
document.title = 'Simple manipulation...';
//document.write('<span class=greeting>Hello World!</span>');
document.write(btoa('test'));
</script>dGVzdA==
</body></html>
Actual behavior:
Output:
<html><head><title>Simple manipulation...</title></head>
<body>
<script>
document.title = 'Simple manipulation...';
//document.write('<span class=greeting>Hello World!</span>');
document.write(btoa('test'));
</script>
</body></html>
Environment details: [Win 10, .NET Framework 4.6.2]
It maybe an obvious question as I don't know the way the library works till now, or just don't know the right way to use it.
Note
- To get the javascript error append these lines:
var service = new JsScriptingService();
var result = service.EvaluateScript(document, "btoa('test')");
Console.WriteLine(result);
-
Exception: System.Reflection.TargetException: 'Object does not match target type.'
generated in EngineExtensions (Call method). -
When appending these lines:
var service = new JsScriptingService();
var result = service.EvaluateScript(document, "btoa");
Console.WriteLine(result);
Appended output:
function btoa() { [native code] }
So, it exists but I can't call it, maybe I'm using it the wrong way.
Thanks for the report - I'll look into it!
Landed in devel
.