Insert text in a website #3983
Replies: 1 comment
-
In what way does it fail? If you debug does it get to the ExecuteScriptAsync line? It looks like your script doesn't try to set the text in the element. You can try something like the following: private async void Web_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
{
var msg = "Hello from a newly loaded .NET window.";
var elem = await web.ExecuteScriptAsync("document.getElementById('grammarbot').textContent = " + System.Text.Json.JsonEncodedText.Encode(msg));
} This will insert the text into the DOM but the way the text is inserted is not expected by the script on the page so it doesn't actually trigger the script that will run the grammar check. You'll need to investigate more the page you're injecting script into to figure out how to do this the way you want. But in terms of WebView2, you are correctly calling CoreWebView2.ExecuteScriptAsync. If you want to pass data in like the above you just must ensure that you are correctly encoding it. |
Beta Was this translation helpful? Give feedback.
-
I have a Webview2, that loads this page https://quillbot.com/grammar-check and a ViewModel, that has text.
What I want to do, is to put my text into the grammar editor
and execute everything in the VM, but because the webview is not MVVM friendly, I had to use code behind
I already tried this
`public SpellCheckWindow()
{
InitializeComponent();
ConfigureSite();
}
`
but it doesn't work
Beta Was this translation helpful? Give feedback.
All reactions