I'm currently using navigator.clipboard.writeText()to copy a value from an element to the clipboard however, its seems to work on all devices apart from the iPhone X and iPhone 6 Plus in safari.
The browsers are up to date and according to MDN they should work with these versions of safari. The code seems to work on desktop, android and other IOS devices (such as the iPhone 12).
On the iPhone X and 6 Plus it throws a Promise error on both of these devices in the console and also doesn't copy to the clipboard:
Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'navigator.clipboard.writeText')
Has anybody experienced anything similar and has seen / come up with a solution? Thanks!
Code snippet:
const coupon = couponSelector.value;
if (notMissing(coupon) && coupon !== '') {
navigator.clipboard
.writeText(coupon)
.then(() =>
LOGGER.debug({}, `${LOGGER_PREFIX}: Promise Successful.Copied coupon: ${coupon}`),
)
.catch((e) => LOGGER.error({ e }, `${LOGGER_PREFIX}: Promise Failed:`));
}