Forum Archive

How to retrieve selected text in ui.WebView?

zipit

Hi, is it possible to get the currently selected text inside a ui.WebView? I am aware that I could copy the text manually to the clipboard and then retrieve its content with Python but I would like to avoid that additional step. I was hoping for some ObjC magic, so that I could invoke the WebViews Edit menue copy function programmatically.

Cheers
zipit

omz

No need for objc_util, you can use JavaScript:

selected_text = web_view.eval_js('document.getSelection().toString()')
zipit

Oh, thanks, that was quick!