Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions web-nfc/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
feature_name: Web NFC
chrome_version: 81
feature_id: 6261030015467520
check_min_version: true
origin_trial: AuUKCGU7HvNzPLMTNDyeZCeo3I1NLuTn/9sPclxgHgJB50gi8hxO3E9VPgH5a8vH+SiDUvxmqoxithPEMQXdNg4AAABWeyJvcmlnaW4iOiJodHRwczovL2dvb2dsZWNocm9tZS5naXRodWIuaW86NDQzIiwiZmVhdHVyZSI6IldlYk5GQyIsImV4cGlyeSI6MTU4NDAyMjYxOX0=
---

<h3>Background</h3>
<p>
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.
</p>

<button id="scanButton">Scan</button>
<button id="writeButton">Write</button>

{% include output_helper.html initial_output_content=initial_output_content %}

<script>
log = ChromeSamples.log;
</script>

{% include js_snippet.html filename='index.js' %}
32 changes: 32 additions & 0 deletions web-nfc/index.js
Original file line number Diff line number Diff line change
@@ -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);
}
});