Well, the above is a generic solution for returning the current selection in the browser window as a string.
However, looks like Document Viewer (looking at their demo page) winds up with the document in an iframe. So you need to do .getSelection() on contents of the iframe.
(BUT you can only do this if the origin of the iframe is same-domain. I’m pretty sure this iframe hosts from Gdrive, right?)
You’d need to expose HTML ID attributes if you haven’t already done so:
Then give your document viewer element an ID (like “keith”). Now you’ll be able to find the iframe like this (if you look at the elements in the console, you’ll see that the iframe is the first child of the bubble element), so:
var frame = document.getElementByID(“keith”).firstElementChild
That’s the iframe. From there, you may or may not be able to do:
var keith_doc = frame.contentDocument
… and then keith_doc.getSelection.toString() would (I believe) give you whatever is selected.
The PROBLEM THOUGH is that the src for the iframe is going to be from Google drive and cross-domain restrictions are going to stop you from getting contentDocument.
So, I don’t think you can successfully do this, but that’s how you’d do it…