button.addEventListener('click', async () => {
try {
const data = {
title: 'MDN',
text: 'Learn web development on MDN!',
url: 'https://developer.mozilla.org',
};
if (navigator.canShare?.(data)) {
await navigator.share(data);
} else {
console.log(`Couldn't share data`);
}
} catch (error) {
console.error(error);
}
});