'GetSelection from metamask

I want the digits inside the selected text to be put in -var selected-. It works very well on webpages, but I want it to work popups from other plugins like metamask. Google translate also use getSelection to search for a selected text and it works inside metamask, but mine does not work inside metamask. All help will be appreciated.

var selected = window.getSelection().toString().replace(/[^\d.]/g, '');



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source