Determining Whether a Selection is Empty

I am reading the contents of a selection to the clipboard using document.execCommand('copy'), and then assigning it to a variable.

There is a possibility that the user will not have any text selected, and instead will simply have clicked in the area.

In that case, the previous contents of the clipboard remain unchanged, since the copy command won’t execute unless there is actually a selection.

Is there a way for me to determine when the selection is empty?

I have could compare the previous and current values of the clipboard, and when they are the same, assigning the selection variable to an empty string, but there could be some edge cases where the selection and the clipboard contents are legitimately the same, and in that case, the function would not work properly.

You may be able to check out the selected text using https://developer.mozilla.org/en-US/docs/Web/API/Selection

If I use window.getSelection() on a content editable text box, I get unavailable whether or not I have text selected or not.

This is why I moved to using document.execCommand('copy') in the first place.