npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chrome-nfc

v0.0.1

Published

Chrome App NFC Library

Downloads

3

Readme

Chrome App NFC Library

With this simple library, you can build a Chrome App that communicates over USB with NFC Readers.

Supported NFC Readers

ACR122U | SCL3711 --- | --- |

Play with the Chrome App sample

  • Check Developer Mode in chrome://extensions
  • Click "Load unpacked extension..." in chrome://extensions and select the sample folder.
  • Launch it.

Caveats

Learn more about USB Devices Caveats at https://developer.chrome.com/apps/app_usb#caveats

Usage

Once you've imported the chrome-nfc.js javascript library into your Chrome App, you need to add the permissions below to your manifest file:

"permissions": [
  "usb",
  {
    "usbDevices": [
      { "vendorId": 1254, "productId": 21905 }, // SCL3711
      { "vendorId": 1839, "productId": 8704 }   // ACR122U
    ]
  }
]

Enumerate NFC readers

chrome.nfc.findDevices(function(devices) {
  console.log("Found " + devices.length + " NFC device(s)");
  for (var i = 0; i < devices.length; i++) {
    var device = devices[i];
    console.log(device.vendorId, device.productId);
  }
});

Read NFC tag

chrome.nfc.findDevices(function(devices) {
  var device = devices[0];
  chrome.nfc.read(device, {}, function(type, ndef) {
    console.lof(ndef);
    var uri = ndef.ndef[0]["uri"];
    console.log(uri);
    var text = ndef.ndef[1]["text"];
    console.log(text);
  });
});

Write NFC tag

chrome.nfc.findDevices(function(devices) {
  var device = devices[0];
  var ndef = [
    {"text": "Chromium.org website" },
    {"uri": "http://chromium.org" },
    {"aar": "com.google.samples.apps.iosched" },
  ];
  chrome.nfc.write(device, {"ndef": ndef}, function(rc) {
    if (!rc) {
      console.log("WRITE() success!");
    } else {
      console.log("WRITE() FAILED, rc = " + rc);
    }
  });
});

Emulate NFC tag

chrome.nfc.findDevices(function(devices) {
  var device = devices[0];
  var ndef = [
    {"type": "URI", "uri": "http://chromium.org"}
  ];
  chrome.nfc.emulate_tag(device, {"ndef": ndef}, function(rc) {
    if (!rc) {
      console.log("EMULATE() success!");
    } else {
      console.log("EMULATE() FAILED, rc = " + rc);
    }
  });
});

Read Mifare Classic tag (Logic Mode)

chrome.nfc.findDevices(function(devices) {
  var device = devices[0];
  chrome.nfc.read_logic(device, 0, 2, function(rc, data) {
    console.log(UTIL_BytesToHex(data));
  });
});

Write Mifare Classic tag (Logic Mode)

chrome.nfc.findDevices(function(devices) {
  var device = devices[0];
  var data = new Uint8Array([ // NDEF(http://google.com)
    0xdb, 0x00, 0x03, 0xe1, 0x00, 0x00, 0x00, 0x00, // block 0 (MAD1)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // block 1 (MAD1)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x03, 0x0f, 0xd1, 0x01, 0x0b, 0x55, 0x03, 0x67, // block 2 (NDEF)
    0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
    0x6d, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // block 3 (NDEF)
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  ]);
  chrome.nfc.write_logic(device, 0, data, function(rc) {
    console.log("WRITE_LOGIC() SUCCESS");
  });
});

Compiling the library

Compiling script requires Python 3.0 and will use online Closure Compiler. Just run

python3 compile.py

and the library will be written to chrome-nfc.js.