NFC API

Non-standard
This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

This API is available on Firefox OS for privileged or certified applications only.

The Near Field Communication (NFC) API is used to exchange data between NFC-enabled mobile devices or NFC tags by tapping them together.

Overview

You access the entire set of NFC functionality through the Navigator.mozNfc property, returning a MozNFC object that further operations can be performed on.

Permission

Privileged applications that want to use the NFC API must request the nfc permission within their app manifest. Firefox 2.2+ allows usage of NFC in privileged apps; previous to that it is only available to certified apps.

"permission": {
  "nfc":{}
}

NFC API supports three modes of operations defined in NFC Forum.

Reader/Writer Mode

This mode can be used to read/write NFC tags through MozNFCTag interface by using MozNDEFRecord, or communicate with the NFC Tag by sending/receiving APDU command.

Peer to Peer Mode

This mode is used to share content with another NFC device through MozNFCPeer interface.

Card Emulation Mode

This mode allows the NFC device to be emulated as an NFC Tag. This mode is mostly used in NFC payments.

As of Firefox OS v2.2, only Secure Element-based Card Emulation is supported.

NDEF Record

NDEF (NFC Data Exchange Format) is the common data format defined in NFC Forum. By using NDEF, an application can operate on the MozNFCTag if the tag is compliant with NFC Forum Tag, or it can exchange data with MozNFCPeer.

See the documentation in MozNDEFRecord.

Event Dispatching 

For the NFC Tag or NFC Peer events, the priority is to dispatch these events to the foreground application first (decided by System application). If the foreground application cannot process the event, the event will be re-dispatched to System app again, then System app will launch applications by invoking MozActivity.

You can find more details on using NFC in Firefox OS in Using the NFC API.

NFC Interfaces

MozNDEFRecord
NFC Data Exchange Format (NDEF) structure for NFC-related data.
MozNFC
Top level Navigator object for NFC operations.
MozNFCTag
NFC object used to manipulate data on tags.
MozNFCPeer
NFC object used to manipulate data on devices.

Specifications

The NFC implementation in Gecko follows the NFC Forum specifications.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support

No support

No support No support No support No support
Feature Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support No support No support 2.0 moz [1] No support No support No support

[1] Available in privileged apps as of Firefox OS 2.2; certified-only before that.

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, fscholz, teoli, kscarfone, allstars.chh, lgarner
 Last updated by: chrisdavidmills,