Search code examples
webnfc

Is reading a NFC chip as a web app possible


I'd like to use Vaadin to create a web app in Java that reads a NFC chip to identify the user and then proceeds with other options, is that possible?

My reason why I don't want to do that in an android app is to decentralize myself to perform the same work for multiple versions and/or different systems


Solution

  • The Web NFC API is what you're looking for: https://web.dev/nfc

    Web NFC is available only on Chrome for Android for now. It is limited to NDEF because the security properties of reading and writing NDEF data are more easily quantifiable. Low-level I/O operations (e.g. ISO-DEP, NFC-A/B, NFC-F), Peer-to-Peer communication mode and Host-based Card Emulation (HCE) are not supported.

    Here's a sample for you to play with: https://googlechrome.github.io/samples/web-nfc/

    const ndef = new NDEFReader();
    await ndef.scan();
    
    ndef.addEventListener("reading", ({ message, serialNumber }) => {
      console.log(`> Serial Number: ${serialNumber}`);
      console.log(`> Records: (${message.records.length})`);
    });