Here's hoping your users never try typing a
'
character in their password!
You need to properly escape the strings that you're passing into the
ExecuteScriptAsync
method. For example:
string encodedUserName = System.Text.Json.JsonSerializer.Serialize(textBox1.Text);
string encodedPassword = System.Text.Json.JsnoSerializer.Serialize(textBox2.Text);
string scriptToExecute = $"document.getElementById('username').value = ${encodedUsername}; document.getElementById('password').value = ${encodedPassword};";
webView21.ExecuteScriptAsync(scriptToExecute);
NB: Do yourself a favour and start giving your controls meaningful names, rather than accepting the defaults suggested by the Visual Studio designer. You might remember which of the 21+
WebView
controls to use for login
today, but when you come back to this code in a few months, you won't have a clue.