Core - EvaluateScriptAsPromiseAsync not working when JavascriptBindingApiGlobalObjectName specified

Resolves #3281
This commit is contained in:
Alex Maitland
2020-11-14 12:07:18 +10:00
parent 145fbab12a
commit e9bbcd6bdd
2 changed files with 26 additions and 3 deletions
@@ -200,6 +200,29 @@ namespace CefSharp.Test.OffScreen
}
}
[Theory]
[InlineData("lowerCustom")]
[InlineData("UpperCustom")]
public async Task CanEvaluateScriptAsPromiseAsyncJavascriptBindingApiGlobalObjectName(string rootObjName)
{
using (var browser = new ChromiumWebBrowser("http://www.google.com", automaticallyCreateBrowser:false))
{
browser.JavascriptObjectRepository.Settings.JavascriptBindingApiGlobalObjectName = rootObjName;
browser.CreateBrowser();
await browser.LoadPageAsync();
var mainFrame = browser.GetMainFrame();
Assert.True(mainFrame.IsValid);
var javascriptResponse = await browser.EvaluateScriptAsPromiseAsync("return new Promise(function(resolve, reject) { resolve(42); });");
Assert.True(javascriptResponse.Success);
Assert.Equal("42", javascriptResponse.Result.ToString());
}
}
[Theory]
[InlineData("return 42;", true, "42")]
[InlineData("return new Promise(function(resolve, reject) { resolve(42); });", true, "42")]
+3 -3
View File
@@ -1014,7 +1014,7 @@ namespace CefSharp
/// When the promise either trigger then/catch this returned Task will be completed.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">Thrown when one or more arguments are outside the required range.</exception>
/// <param name="chromiumWebBrowser">The ChromiumWebBrowser instance this method extends.</param>
/// <param name="frame">The <seealso cref="IFrame"/> instance this method extends.</param>
/// <param name="script">The Javascript code that should be executed.</param>
/// <param name="timeout">(Optional) The timeout after which the Javascript code execution should be aborted.</param>
/// <returns>
@@ -1039,11 +1039,11 @@ namespace CefSharp
if (char.IsLower(internalJsFunctionName[0]))
{
internalJsFunctionName += "sendEvalScriptResponse";
internalJsFunctionName += ".sendEvalScriptResponse";
}
else
{
internalJsFunctionName += "SendEvalScriptResponse";
internalJsFunctionName += ".SendEvalScriptResponse";
}
}
var promiseHandlerScript = "let innerImmediatelyInvokedFuncExpression = (function() { " + script + " })(); Promise.resolve(innerImmediatelyInvokedFuncExpression).then((val) => " + internalJsFunctionName + "(cefSharpInternalCallbackId, true, val)).catch ((reason) => " + internalJsFunctionName + "(cefSharpInternalCallbackId, false, String(reason))); return 'CefSharpDefEvalScriptRes';";