-
Notifications
You must be signed in to change notification settings - Fork 54
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
WebView2 ExecuteScriptAsync fails when script is executed a second time #4124
Comments
Hi, your issue is with JS, not ExecuteScript API - you are redeclaring |
Thanks for the response, but I don't understand what you mean. I am a novice to JS so you probably have a point. I tried to declare clickButton at the top of the script an use it further down. |
I was thinking
Hope it make sense |
Thanks again. I will try it out tomorrow. |
Fantastic! It worked. I've never seen a tutorial/example that utilizes this pattern. Thanks again! |
What happened?
Microsoft.Web.WebView2 1.0.2164-prerelease
Running the script once is OK.
Running the script a second time results in an exception.
Is this an error or a limitation?
Is there a way to "clean up" between script executions?
Script:
let clickButton = function (doc, buttonId) {
let button = doc.getElementById(buttonId);
if (button != null) {
button.click();
}
};
const nextButtonId = "someButtonId";
clickButton(document, nextButtonId);
//...More script code...
Exception from ExecuteScriptWithResultAsync:
{
"columnNumber": 0,
"exception": {
"className": "SyntaxError",
"description": "SyntaxError: Identifier 'clickButton' has already been declared",
"objectId": "-8654842674382291014.2.2",
"subtype": "error",
"type": "object"
},
"exceptionId": 1,
"lineNumber": 0,
"scriptId": "61",
"text": "Uncaught"
}
Importance
Moderate. My app's user experience is affected, but still usable.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
118.0.2088.76
SDK Version
1.0.2164.0
Framework
WPF
Operating System
Windows 10
OS Version
19045.3636
Repro steps
Execute script twice
Regression
Don't know
Last working version (if regression)
No response
The text was updated successfully, but these errors were encountered: