ContactsManager.getProperties()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

getProperties()ContactsManager インターフェイスのメソッドで、プロミス (Promise) を返します。これは、どの連絡先プロパティが利用できるかを示す文字列の配列 (Array) で解決します。

構文

js
getProperties()

引数

このメソッドは引数を受け取りません。

返値

プロミス (Promise) を返します。これは、どの連絡先プロパティが利用できるかを示す文字列の配列 (Array) で解決します。

プロパティには、以下のものを含めることができます。

  • 'name': 連絡先の名前。
  • 'tel': 連絡先の電話番号。
  • 'email': 連絡先のメールアドレス。
  • 'address': 連絡先の住所。
  • 'icon': 連絡先のアバター。

例外

発生する例外はありません。

プロパティの対応を確認

以下の非同期関数は getProperties() メソッドを使用して、現在のシステムが icon プロパティに対応しているかどうかを調べています。

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

対応しているプロパティのみを使用して選択

以下の例は select() メソッドと似ています。 select() に渡されるプロパティをハードコーディングする代わりに、 getProperties() を使用して、対応しているプロパティのみが渡されるようにします。そうでない場合、 select()TypeError を発生させるかもしれません。 handleResults() は開発者が定義した関数です。

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.
  }
}

仕様書

Specification
Contact Picker API
# contacts-manager-getproperties

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getProperties
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
User must explicitly enable this feature.