I am attempting to get the currently selected text from an arbitrary website shown in a UWP WebView to the UWP App written in C#. I have tried several methods, but the Async calls:-
return await myWebView.InvokeScriptAsync("eval", new string[] { "return document.getSelection.toString();" });
,
await myWebView.InvokeScriptAsync("eval", new string[] { "document.body.innerHTML = document.getSelection.toString();" });
and
DataPackage data = await web.CaptureSelectedContentToDataPackageAsync();
return await data.GetView().GetTextAsync();
keep hanging and causing an infinite loop.
I have gotten simple DOM Model editing code to be injected via the InvokeScriptAsync, but as soon as I try document.getSelection() or window.getSelection(), the whole program just freezes forever.
I saw this post Windows UWP - WebView get selected Text but that does seem to be working for me, even though I am working on a PC.