Copyright © 2014 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. W3C liability, trademark and document use rules apply.
Near Field Communication (NFC) is an international standard (ISO/IEC 18092) that specifies an interface and protocol for simple wireless interconnection of closely coupled devices operating at 13.56 MHz. (see http://www.nfc-forum.org/specs/spec_list/). There are three groups of application scenarios for NFC:
NFC enables wireless communication between two devices at close proximity, usually less than a few centimeters.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document defines an API for access to the hardware subsystem for near field communications (NFC). It permits Web pages to read and write NFC tags, to send and receive messages between NFC devices, and to handover to WiFi or Bluetooth.
This document was published by the NFC working group as a First Public Working Draft. This document is intended to become a W3C Recommendation. If you wish to make comments regarding this document, please send them to public-nfc@w3.org (subscribe, archives). All comments are welcome.
Publication as a First Public Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
Navigator
        object
        
      NFCManager
        Interface
        
      NFCTagEvent
        Interface
        
      NFCPeerEvent
        Interface
        
      NDEFMessageEvent
        Interface
        
      NFCTag Interface
        
      NFCPeer Interface
        
      NDEFMessage
        Interface
        
      NDEFRecord
        Interface
        
      NDEFRecordText
        Interface
        
      NDEFRecordURI
        Interface
        
      NDEFRecordMedia
        Interface
        
      NDEFRecordSmartPoster
        Interface
        
      This section is non-normative.
The NFC API supports the following features:Here are some possible use cases:
NFCPeer interface to
        exchange NDEF messages.
      NFCPeer interface to
        exchange NDEF messages.
      NFCPeer interface.
      NFCPeer
        interface.
      NFCTag interface.
      NFCTag interface.
      An example of use is provided below:
var hello = new NDEFRecordText("hello world", "en-US", "UTF-8"); navigator.nfc.ontagfound = function(e) { window.console.log('NFC Tag found!'); var tag = e.tag; tag.writeNDEF(new NDEFMessage([hello])); } navigator.nfc.startPoll().catch( function(e) { window.console.error(e); });
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MUST, MUST NOT, REQUIRED, SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL in this specification are to be interpreted as described in [RFC2119].
This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.
Implementations that use ECMAScript to implement the APIs defined in this specification MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [WEBIDL], as this specification uses that specification and terminology.
The 
    EventHandler interface represents a callback
    used for event handlers as defined in [HTML5].
The concepts queue a task and fire a simple event are defined in [HTML5].
The terms event handler and event handler event types are defined in [HTML5].
The Event
    interface and the Promise
    interface as well as the concept of a resolver are defined in
    [DOM4].
A NFC tag is a passive, unpowered NFC device. The NFC tag is powered by magnetic induction when an active NFC device is in close vicinity. A NFC tag contains a single NDEF message.
A NDEF message encapsulates one or more application-defined NDEF records. NDEF stands for NFC Forum Data Exchange Format, a lightweight binary message format. NDEF messages can be stored on a NFC tag or exchanged between NFC-enabled devices.
A NDEF record has a maximum payload of 2^32-1 bytes. The record also contains information about the payload size, type, and an optional identifier.
NFCManager
    InterfaceThe NFCManager interface
    defines access to NFC functionality and offers methods to
    control local NFC behavior like polling for targets.
[NoInterfaceObject]
interface NFCManager : EventTarget {
    readonly    attribute boolean      powered;
    readonly    attribute boolean      polling;
    Promise powerOn ();
    Promise powerOff ();
    Promise startPoll ();
    Promise stopPoll ();
                attribute EventHandler onpoweron;
                attribute EventHandler onpoweroff;
                attribute EventHandler onpollstart;
                attribute EventHandler onpollstop;
                attribute EventHandler ontagfound;
                attribute EventHandler ontaglost;
                attribute EventHandler onpeerfound;
                attribute EventHandler onpeerlost;
};
    onpeerfound of type EventHandler,peerfound event of type NFCPeerEventNFCPeer is detected
          by the NFC manager. The peer property
          of the event MUST
          contain the corresponding NFCPeer object.
        onpeerlost
        of type EventHandler,peerlost
        event is dispatched.onpollstart of type EventHandler,pollstart
        event is dispatched.onpollstop
        of type EventHandler,pollstop
        event is dispatched.onpoweroff
        of type EventHandler,poweroff
        event is dispatched.onpoweron
        of type EventHandler,poweron
        event is dispatched.ontagfound
        of type EventHandler,tagfound event of type NFCTagEventNFCTag is detected by
          the NFC manager. The tag property of
          the event MUST
          contain the corresponding NFCTag object.
        ontaglost
        of type EventHandler,taglost
        event is dispatched.polling of
        type boolean,
        readonlypowered of
        type boolean,
        readonlypowerOffPromise to notify the caller that the NFC
          hardware power is turned off.
          Promise
          powerOnPromise to notify the caller that the NFC
          hardware is now powered.
          Promise
          startPollPromise to notify the caller
          that the NFC hardware is now polling.
          Promise
          stopPollPromise to notify the caller
          that the NFC hardware stopped polling.
          Promise
          The following are the event handlers (and their corresponding event handler types) that MUST be supported as attributes by the NFC object.
| event handler | event name | event type | short description | 
|---|---|---|---|
| onpoweron | poweron | simple event | fired when the poweredstate changes
            totrue | 
| onpoweroff | poweroff | simple event | fired when the poweredstate changes
            tofalse | 
| onpollstart | pollstart | simple event | fired when the pollingstate changes
            totrue | 
| onpollstop | pollstop | simple event | fired when the pollingstate changes
            tofalse | 
| ontagfound | tagfound | with tag property set to the newNFCTagobject. | detect a new NFCTag | 
| ontaglost | taglost | simple event | fired when the NFCTagdetected by the
            adaptor moves out of range. | 
| onpeerfound | peerfound | with peer property set to the newNFCPeerobject. | detect a new NFCPeer | 
| onpeerlost | peerlost | simple event | fired when the NFCPeerdetected by the
            adaptor moves out of range. | 
NFCTagEvent
    Interface
interface NFCTagEvent : Event {
    readonly    attribute NFCTag tag;
};
    tag of type
        NFCTag,
        readonlyNFCTag that triggered
          the event.
        NFCPeerEvent
    Interface
interface NFCPeerEvent : Event {
    readonly    attribute NFCPeer peer;
};
    peer of type
        NFCPeer,
        readonlyNFCPeer that
          triggered the event.
        NDEFMessageEvent
    Interface
interface NDEFMessageEvent : Event {
    readonly    attribute NDEFMessage message;
};
    message
        of type NDEFMessage,
        readonlyNDEFMessage that
          triggered the event.
        NFCTag Interface
[NoInterfaceObject]
interface NFCTag {
    Promise readNDEF ();
    Promise writeNDEF (NDEFMessage message);
};
    readNDEFPromise that will notify the caller with the
          result of the operation, which is a NDEFRecord.
          Promise
          writeNDEFPromise to notify the
          caller about the operation success or failure.
          | Parameter | Type | Nullable | Optional | Description | 
|---|---|---|---|---|
| message |  | ✘ | ✘ | The NDEF message to write on the NFC Tag | 
Promise
          NFCPeer Interface
[NoInterfaceObject]
interface NFCPeer : EventTarget {
    Promise sendNDEF (NDEFMessage message);
    Promise startHandover (HandoverType handoverType);
                attribute EventHandler onmessageread;
};
    onmessageread of type EventHandler,messageread event of type
          NDEFMessageEventNDEFMessage is
          sent by the peer device. The message
          property of the event MUST contain the corresponding NDEFMessage
          object.
        sendNDEFPromise to
          notify the caller about the operation success or failure.
          | Parameter | Type | Nullable | Optional | Description | 
|---|---|---|---|---|
| message |  | ✘ | ✘ | The NDEF message to send to the NFC peer device. | 
Promise
          startHandoverPromise to notify the caller about the
          operation success or failure.
          | Parameter | Type | Nullable | Optional | Description | 
|---|---|---|---|---|
| handoverType |  | ✘ | ✘ | Select "wifi"or"bluetooth"pairing. | 
Promise
          The following are the event handlers (and their
      corresponding event handler types) that MUST be supported as attributes
      by the NFCPeer object.
| event handler | event name | event type | short description | 
|---|---|---|---|
| onmessageread | messageread | with message property set to the newNDEFMessageobject. | fired when a NDEFMessageis sent by
            the peer device. | 
NDEFMessage
    Interface
[
Constructor(byte[]bytes)
Constructor(NDEFRecord[]records)
]
interface NDEFMessage {
    readonly    attribute NDEFRecord[] records;
    Promise getBytes ();
};
    records of
        type array of NDEFRecord,
        readonlyNDEFRecord objects part of the
          NDEF
          message. Otherwise it MUST return an empty list.
        getBytesPromise to notify
          the caller with the result of the operation, which is of
          type byte[] i.e. a Javascript Array of
          Number objects.
          Promise
          NDEFRecord
    Interface
[
Constructor(byte tnf, 
  optional DOMString type, 
  optional byte[]payload, 
  optional DOMString id)
]
interface NDEFRecord {
    readonly    attribute NDEFRecordType recordType;
    readonly    attribute byte           tnf;
    readonly    attribute DOMString?     type;
    readonly    attribute DOMString?     id;
    Promise getPayload ();
};
    id of type
        DOMString, readonly
        , nullablerecordType
        of type NDEFRecordType,
        readonlytnf of type
        byte, readonlytype of type
        DOMString, readonly
        , nullablegetPayloadPromise to notify the caller
          with the result of the operation, which is of type
          byte[] i.e. a Javascript Array of Number
          objects.
          Promise
          NDEFRecordText
    Interface
[Constructor(DOMString text, 
             optional DOMString languageCode,
             optional DOMString encoding)]
interface NDEFRecordText : NDEFRecord {
    readonly    attribute DOMString text;
    readonly    attribute DOMString languageCode;
    readonly    attribute DOMString encoding;
};
    encoding
        of type DOMString,
        readonlylanguageCode of type DOMString, readonlytext of type
        DOMString,
        readonlyNDEFRecordURI
    Interface
[Constructor(DOMString uri)]
interface NDEFRecordURI : NDEFRecord {
    readonly    attribute DOMString uri;
};
    uri of type
        DOMString,
        readonlyNDEFRecordMedia
    Interface
[Constructor(DOMString mimeType,
             byte[]payload)]
interface NDEFRecordMedia : NDEFRecord {
    readonly    attribute DOMString mimeType;
};
    mimeType of type DOMString, readonlyNDEFRecordSmartPoster
    Interface
[Constructor(DOMString uri,
             optional NDEFRecordText[]titles,
             optional DOMString action,
             optional NDEFRecordMedia[]icons,
             optional unsigned long targetSize,
             optional DOMString targetMIME)]
interface NDEFRecordSmartPoster : NDEFRecord {
    readonly    attribute DOMString          uri;
    readonly    attribute NDEFRecordText[]?  titles;
    readonly    attribute SmartPosterAction? action;
    readonly    attribute NDEFRecordMedia[]? icons;
    readonly    attribute unsigned long?     targetSize;
    readonly    attribute DOMString?         targetMIME;
};
    action of type SmartPosterAction,
        readonly , nullableicons of type array of NDEFRecordMedia,
        readonly , nullabletargetMIME of type DOMString, readonly ,
        nullabletargetSize of type unsigned long, readonly ,
        nullabletitles of type array of NDEFRecordText,
        readonly , nullableuri of
        type DOMString,
        readonlyThe attribute recordType can have the following
    values:
enum NDEFRecordType {
    "text",
    "uri",
    "media",
    "smartPoster",
    "unknown"
};
    | Enumeration description | |
|---|---|
| text | Corresponding to NDEFRecordText. | 
| uri | Corresponding to NDEFRecordURI. | 
| media | Corresponding to NDEFRecordMedia. | 
| smartPoster | Corresponding to NDEFRecordSmartPoster. | 
| unknown | Corresponding to the base NDEFRecord interface. | 
The attribute action can have the following
    values:
enum SmartPosterAction {
    "do",
    "save",
    "open"
};
    | Enumeration description | |
|---|---|
| do | Do the action. For instance, send a SMS, dial a phone number, or open a URI. | 
| save | Store a SMS, bookmark a URI, save a phone number in the address book. | 
| open | Open for edition. | 
The attribute handoverType can have the
    following values:
enum HandoverType {
    "wifi",
    "bluetooth"
};
    | Enumeration description | |
|---|---|
| wifi | Initiate WiFi handover. | 
| bluetooth | Initiate bluetooth pairing. | 
The editors would like to thank Jaehyun Park and Taehee Lee of Samsung for their work on the initial API design. We would also like to thank the members of the W3C SysApps group for their help on the API specification process, and the members of the W3C NFC group for their feedback on this API.