diff --git a/web-nfc/index.html b/web-nfc/index.html new file mode 100644 index 0000000000..68289356ef --- /dev/null +++ b/web-nfc/index.html @@ -0,0 +1,27 @@ +--- +feature_name: Web NFC +chrome_version: 81 +feature_id: 6261030015467520 +check_min_version: true +origin_trial: AuUKCGU7HvNzPLMTNDyeZCeo3I1NLuTn/9sPclxgHgJB50gi8hxO3E9VPgH5a8vH+SiDUvxmqoxithPEMQXdNg4AAABWeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZWNocm9tZS5naXRodWIuaW86NDQzIiwiZmVhdHVyZSI6IldlYk5GQyIsImV4cGlyeSI6MTU4NDAyMjYxOX0= +--- + +
+Web NFC aims to provide sites the ability to read and write to NFC tags when +they are brought in close proximity to the user’s device (usually 5-10 cm, 2-4 +inches). The current scope is limited to NDEF, a lightweight binary message +format. Low-level I/O operations (e.g. ISO-DEP, NFC-A/B, NFC-F) and Host-based +Card Emulation (HCE) are not supported within the current scope. +
+ + + + +{% include output_helper.html initial_output_content=initial_output_content %} + + + +{% include js_snippet.html filename='index.js' %} diff --git a/web-nfc/index.js b/web-nfc/index.js new file mode 100644 index 0000000000..62fd8a86fe --- /dev/null +++ b/web-nfc/index.js @@ -0,0 +1,32 @@ +scanButton.addEventListener("click", async () => { + log("User clicked scan button"); + + try { + const reader = new NDEFReader(); + await reader.scan(); + log("> Scan started"); + + reader.addEventListener("error", () => { + log("Argh! Cannot read data from the NFC tag. Try a different one?"); + }); + + reader.addEventListener("reading", ({ message, serialNumber }) => { + log(`> Serial Number: ${serialNumber}`); + log(`> Records: (${message.records.length})`); + }); + } catch (error) { + log("Argh! " + error); + } +}); + +writeButton.addEventListener("click", async () => { + log("User clicked write button"); + + try { + const writer = new NDEFWriter(); + await writer.write("Hello world!"); + log("> Message written"); + } catch (error) { + log("Argh! " + error); + } +});