title: Manually trigger cut/copy/paste in android webview
body: <p>I'm building a little browser app using android webview and I've been using <code>window.getSelection()</code> in javascript to get the nature of any text selected by the user and show a custom context menu based on the type of the selection i.e. whether it's a range, a carat, whether it's in a contenteditable etc.</p>
  
  <p>This works fine unless the selection is in an iframe, then the browser security measures kick in and prevent me sniffing what has been selected using <code>window.getSelection()</code>. How can I workaround this?</p>
  
  <p>Ideally I need a way to get better information about what was selected from the webview or if that's not possible I need a way to sniff whether the selection occurred in an iframe so I can disable my custom context menu logic and fallback to the default android context menu.</p>
  
  <p><strong>UPDATE/FURTHER CLARIFICATION 07/05/2019:</strong></p>
  
  <p>Seems I wasn't clear enough in my initial description... </p>
  
  <p>My goal is to have a visually and functionally <em>custom</em> menu when selecting content in the webview that can cut/copy/paste as the standard context menu does in any part of the page/iframes etc. e.g.</p>
  
  <p><a href="https://i.stack.imgur.com/O5zIP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O5zIP.png" alt="example custom menu"></a></p>
  
  <p>I realised my original approach using javascript to detect the type of selection and to perform the cut/copy/paste was wrong because it will be blocked by cross origin security in iframes. </p>
  
  <p>What I need is a native android/webview based approach. I've discovered that I can sniff the type of selection in the webview by looking at the items in <code>mode.getMenu()</code> on <code>onActionModeStarted</code>. This will allow me to show the correct buttons in my custom menu UI but I have been unable to manually trigger the same logic that gets called when cut/copy/paste is clicked. I thought I found the solution with <code>webView.performAccessibilityAction(AccessibilityNodeInfo.ACTION_CUT, null);</code> but this doesn't work for some reason so I guess my question really is how can I manually trigger cut/copy/paste on the selected text from webview without using javascript? or any other approach that will allow me to have a custom selection menu with lots of options based on what was selected without hitting the browser security limitations?</p>