W3cubDocs

/Web APIs

ContactsManager: getProperties() method

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The getProperties() method of the ContactsManager interface returns a Promise which resolves with an Array of strings indicating which contact properties are available.

Syntax

js

getProperties()

Parameters

This method receives no parameters.

Return value

Returns a Promise that resolves with an Array of strings naming the contact properties that can be returned by the current system.

Properties can include the following:

  • 'name': The contact's name.
  • 'tel': The telephone number(s) of the contact.
  • 'email': The email address of the contact.
  • 'address': The contact's postal address.
  • 'icon': The avatar of the contact.

Exceptions

No exceptions are thrown.

Examples

Verify Property Support

The following asynchronous function uses the getProperties() method to check whether the current system supports the icon property.

js

async function checkProperties() {
  const supportedProperties = await navigator.contacts.getProperties();
  if (!supportedProperties.includes("icon")) {
    console.log("Your system does not support getting icons.");
  }
}

Select Using Only Supported Properties

The following example is similar to one for the select() method. Instead of hard-coding the properties passed to select(), it uses getProperties() to ensure that only supported properties are passed. Otherwise, select() might throw a TypeError. handleResults() is a developer defined function.

js

const supportedProperties = await navigator.contacts.getProperties();

async function getContacts() {
  try {
    const contacts = await navigator.contacts.select(supportedProperties);
    handleResults(contacts);
  } catch (ex) {
    // Handle any errors here.
  }
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
getProperties No No No No No No 80 80 No 57 14.5
14.0–22.0This API was exposed but failed upon opening a contact selector.

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ContactsManager/getProperties