mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 04:00:07 +00:00
Core - EvaluateScriptAsPromiseAsync not working when JavascriptBindingApiGlobalObjectName specified
Resolves #3281
This commit is contained in:
@@ -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")]
|
||||
|
||||
@@ -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';";
|
||||
|
||||
Reference in New Issue
Block a user