Contacts Picker API
Introduction
Android and IOS applications (native apps) inherently had the capability to access contact list of a user. Ofcouse the user needs to provide permission for that (I think) but it was there. The web however did not have this feature.
Starting from chrome 80, we have support for this feature on android. The user experience is not as great or as powerful as native implementation, but it is not bad by any means. I can see usage of this feature in let's say
- Share trip data to contacts.
- Share gift purchase information.
- Upload and share contact information with ease.
- Sending mails to people from contact list, gone are the days when you need to remember email ids.
and much more...
Demo
Run this application on an android device using the chrome browser.
Source Code
Check the source code on codesandbox.
Getting started
- We need a https domain for this feature to work. Usually these powerful features need extra security for good reasons usually.
- Chrome browser version should be >= 80, which was released in Feb, 2020
-
Check if contacts is supported by the browser.
const supported = "contacts" in navigator && "ContactsManager" in window;
-
Use the async method to prompt the user to select permission and then pick the contacts.
const props = ["name", "email", "tel"]; const opts = { multiple: true }; const contacts = await navigator.contacts.select(props, opts);
- Contacts are an array of objects, so loop through this data and manipulate it as you wish.
- Bonus point, I used ant-design for this project. This allowed me to create this beautiful UI really fast.
Conclusion
I believe this feature is production ready and going forward we can see companies adopting this feature to make better user experiences. Although a compatibility issue is there, but it a "nice" step forward.