Lesson 20 / 29
Contacts Picker API
Access device contacts with user permission using the Contacts Picker API.
Contact access permission
The Contacts Picker API lets users grant permission to your app to read contact information. Users choose which contacts to share, maintaining privacy.
Access contacts
Use the Contacts Picker API to access device contacts with user selection.
const contactsButton = document.getElementById('select-contact');
contactsButton.addEventListener('click', async () => {
try {
const [contact] = await navigator.contacts.select(['name', 'email'], { multiple: false });
console.log('Selected contact:', contact);
} catch (err) {
console.error('Contacts Picker error:', err);
}
});
Output:
User can select contacts from device; app receives selected contact info.