clipboard-apis
clipboard-apis copied to clipboard
Add method `match` (`clipboard.match(regex)`) to check clipboard for pattern matching before reading - as it is done in iOS
Hi! The clipboard is a powerful thing and it can be used to predict user actions - as it is already used in mobile devices.
Idea
In order for the user's data to be safe, you need to ask permission before reading.
But before asking, we could check the contents for the presence of a pattern - at the same time, we do not receive data, but only information(true/false) about whether the contents of the clipboard correspond to our pattern. This is already available in native mobile apps.
Suggestion
I suggest thinking about implementing this behavior in browsers. This will allow us to process such cases, for example - a user logged in to the Internet banking website with a phone number in the clipboard - we can immediately offer to make a money transfer to this number, saving the user time
Promise<boolean> match(RegExp reg);
Usage examples
This will allow us to process such cases, for example - a user logged in to the website with a phone number in the clipboard - we can immediately offer to make a money transfer to this number, saving the user time
const phoneNumberReg = ^(\([0-9]{3}\)|[0-9]{3}-)[0-9]{3}-[0-9]{4}$;
// ask only if necessary
navigator.clipboard.match(phoneNumberReg).then(
(res) => {
if(res) {
return navigator.clipboard.readText();
}
}
);
Native Apps and Web Apps
Let's close the feature gap!
hi, @garykac (and other contributors, I don't know who it would be more correct to call) what do you think about it?:)