Chrome Tips by theluckystrike

Chrome Web NFC Tag Read and Write – Complete Guide

Web technologies continue to bridge the gap between physical and digital worlds, and the Web NFC API is a perfect example of this progress. If you have ever wondered how to interact with NFC tags directly from your Chrome browser, you are in the right place. This guide walks you through reading and writing NFC tags using Chrome on compatible devices.

What Is Web NFC?

Web NFC is a browser API that allows web pages to read and write NFC tags when a device supports NFC hardware. NFC stands for Near Field Communication, a short-range wireless technology commonly used for contactless payments, transit cards, and smart tags. With Web NFC, you can build web applications that interact with these tags without needing a native app.

Chrome became one of the first browsers to implement Web NFC, making it accessible to users on Android devices with Chrome version 89 and later. This opens up possibilities for inventory management, attendance tracking, interactive experiences, and more.

Device Compatibility Requirements

Before you start, it is essential to understand the hardware and software requirements. Web NFC works only on devices with NFC capability. Desktop computers rarely have NFC hardware built in, so you will primarily use this on smartphones or tablets.

Your device must run Chrome for Android version 89 or higher. The NFC tag must also be formatted in a supported format, typically NDEF (NFC Data Exchange Format). Most commercially available NFC tags come pre-formatted as NDEF, so you should not run into issues there.

On the browser side, you also need to serve your page over HTTPS. The Web NFC API is restricted to secure contexts, which means your site must use HTTPS (or localhost for testing).

Reading NFC Tags with Web NFC

Reading an NFC tag is the simpler of the two operations. You start by checking whether the Web NFC API is available in the browser. Then, you define what happens when a tag is scanned.

Here is a basic example of how to read an NFC tag:

if ("NDEFReader" in window) {
  const ndef = new NDEFReader();

  ndef.scan().then(() => {
    console.log("Scan started successfully");
    ndef.onreading = event => {
      const decoder = new TextDecoder();
      for (const record of event.message.records) {
        console.log("Record type:", record.recordType);
        console.log("Data:", decoder.decode(record.data));
      }
    };
  }).catch(error => {
    console.error("Scan failed", error);
  });
}

This code creates an NDEFReader instance, starts scanning for tags, and processes any data found on the tag when it is brought close to the device. The data on an NFC tag can contain different types of records, such as text, URLs, or custom data. The TextDecoder is used to convert the raw bytes into readable text.

One practical use case for reading is a museum exhibit that provides additional information when you tap a tag next to an artwork. Another is a warehouse system where scanning a tag instantly pulls up product details on a web page.

Writing Data to NFC Tags

Writing to NFC tags requires slightly more setup because you need to define the data you want to store. The process involves creating an NDEFMessage with one or more records, then writing that message to a tag.

Here is how you can write to an NFC tag:

if ("NDEFReader" in window) {
  const ndef = new NDEFReader();

  ndef.write({
    records: [{ recordType: "text", data: "Hello from Chrome Web NFC" }]
  }).then(() => {
    console.log("Tag written successfully");
  }).catch(error => {
    console.error("Write failed", error);
  });
}

This example writes a simple text record to the tag. You can also write URLs, MIME type data, or even custom payload types depending on your application needs.

When writing tags, keep in mind that some NFC tags can be locked to prevent further modifications. Make sure your tags are rewritable if you plan to update them later.

Handling Permissions and User Interaction

Chrome requires explicit user permission before your web page can interact with NFC. This means your code must request access, and the user must grant it. The permission prompt appears automatically when you call the scan or write method for the first time.

For a smooth user experience, always explain to users what will happen before they scan a tag. For example, you might display a button that says “Scan Tag” and only initiate the NFC scanning after the user clicks it. This makes the interaction clear and avoids unexpected permission prompts.

It is also worth handling cases where NFC is not available. Not all devices support Web NFC, and some users might have NFC disabled in their settings. Include fallback messaging so your page remains functional even without NFC support.

Practical Applications

The Web NFC API enables many creative and business applications. Retail stores can use it for price checks by tagging products with NFC labels that customers scan to view product details on their phones. Event organizers can track attendance by having attendees tap their phones at stations. Schools can create interactive learning materials where students tap physical objects to access digital content.

If you are building a productivity tool, consider how NFC can streamline workflows. For instance, you could create a system where tapping a tag on your desk automatically opens your daily task list in the browser. Pair this with Tab Suspender Pro to manage your open tabs efficiently, and you have a powerful setup for staying organized throughout the day.

Testing Your Implementation

Testing Web NFC can be tricky because you need physical tags and a compatible device. For development, you can use Chrome DevTools on a connected Android device. Enable USB debugging in developer options, then navigate to chrome://inspect/#devices in Chrome on your desktop to debug your web page running on the phone.

When testing, keep the NFC antenna location in mind. On most phones, the NFC antenna is near the back camera or the upper part of the device. Hold the tag close to that area for reliable detection.

Limitations and Future Outlook

Web NFC currently works only on Chrome for Android. Other browsers have not yet implemented the API, though it is part of the Web Platform Incubator Community Group specifications. If you need cross-browser support, you may need to complement your web solution with a native app.

Also note that NFC interactions are short-range and require physical proximity. This makes them secure for some use cases but limits throughput compared to other wireless technologies.

Despite these limitations, Web NFC represents a significant step forward in making physical and digital experiences work together seamlessly.


Built by theluckystrike — More tips at zovo.one