-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Enhancement - Add EvaluateScriptAsPromiseAsync #3251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement - Add EvaluateScriptAsPromiseAsync #3251
Conversation
- Add useImmediatelyInvokedFuncExpression param to EvaluateScriptAsync which wraps the script in an IIFE with the cefSharpInternalCallbackId variable defined in scope to allow for deferred completion - Wrap script in Immediately Invoked Function Expression and call promise.resolve to guarantee a promise. - Return 'CefSharpDefEvalScriptRes' as the result of the js function to defer execution of the callback - Call newly added cefSharp.sendEvalScriptResponse method in javascript when promise has been resolved/rejected This is built up of a few parts and can technically be used by the new user to defer the response until they are ready. Just return `'CefSharpDefEvalScriptRes'` and manually call cefSharp.sendEvalScriptResponse using the cefSharpInternalCallbackId variable which is injected into the script execution (wrapped in an IIFE to limit scope)
5233955
to
3aa2c6b
Compare
✅ Build CefSharp 85.3.120-CI3720 completed (commit 9bbab0c711 by @amaitland) |
NOTE //Will wait forever unless you call cefSharp.sendEvalScriptResponse yourself
browser.EvaluateScriptAsync("return 'CefSharpDefEvalScriptRes'");
//Will wait forever unless you call cefSharp.sendEvalScriptResponse yourself
browser.EvaluateScriptAsPromiseAsync("return 'CefSharpDefEvalScriptRes'"); |
Developing features like this takes considerably time and effort, if you use |
- Add useImmediatelyInvokedFuncExpression param to EvaluateScriptAsync which wraps the script in an IIFE with the cefSharpInternalCallbackId variable defined in scope to allow for deferred completion - Wrap script in Immediately Invoked Function Expression and call promise.resolve to guarantee a promise. - Return 'CefSharpDefEvalScriptRes' as the result of the js function to defer execution of the callback - Call newly added cefSharp.sendEvalScriptResponse method in javascript when promise has been resolved/rejected This is built up of a few parts and can technically be used by the new user to defer the response until they are ready. Just return `'CefSharpDefEvalScriptRes'` and manually call cefSharp.sendEvalScriptResponse using the cefSharpInternalCallbackId variable which is injected into the script execution (wrapped in an IIFE to limit scope)
this method do not support object, need basic type |
Promise return complex object Issue #3251
Promise return complex object Issue #3251
I've added an additional test in dadb4fa and objects are working as expected.
If you are trying to return a You are welcome to submit a |
#3314 adds the return await 42; |
Summary:
Use newly added
EvaluateScriptAsPromiseAsync
extension method (addusing CefSharp;
) to evaluate javascript thatreturns a promise. Uses
Promise.resolve
to return the script execution into a promise regardless,EvaluateScriptAsPromiseAsync("return 53")
will be turned into a promise.Differs from other
EvaluateScriptAsync
methods in that you must return a result.Changes:
with the cefSharpInternalCallbackId variable defined in scope to allow for deferred completion
This is built up of a few parts and can technically be used by the new user to defer the response until they are ready.
Just return
'CefSharpDefEvalScriptRes'
and manually call cefSharp.sendEvalScriptResponse using the cefSharpInternalCallbackIdvariable which is injected into the script execution (wrapped in an IIFE to limit scope)
How Has This Been Tested?
Basic unit test has been added.
Types of changes
Checklist: