Skip to content

Commit 5e5e51d

Browse files
committed
Revert "Add navigator.nfc and navigator.nfc.ndef objects"
1 parent e7974ae commit 5e5e51d

File tree

3 files changed

+195
-207
lines changed

3 files changed

+195
-207
lines changed

EXPLAINER.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ when required, about granting access to Web NFC. It means sending and receiving
9292
info when users tap NFC devices can be done smoothly once permission is granted.
9393

9494
```js
95+
const reader = new NDEFReader();
96+
9597
async function startScanning() {
96-
await navigator.nfc.ndef.scan();
97-
navigator.nfc.ndef.onreading = event => {
98+
await reader.scan();
99+
reader.onreading = event => {
98100
/* handle NDEF messages */
99101
};
100102
}
@@ -124,8 +126,10 @@ cases where the text might even be in UTF-16 do to existing real life
124126
implementations.
125127

126128
```js
127-
await navigator.nfc.ndef.scan();
128-
navigator.nfc.ndef.onreading = event => {
129+
const reader = new NDEFReader();
130+
131+
await reader.scan({ recordType: "example.com:smart-poster" });
132+
reader.onreading = event => {
129133
const externalRecord = event.message.records.find(
130134
record => record.type == "example.com:smart-poster"
131135
);
@@ -159,9 +163,10 @@ abortController.signal.onabort = event => {
159163
// All NFC operations have been aborted.
160164
};
161165

162-
navigator.nfc.ndef.scan({ signal: abortController.signal });
166+
const ndef = new NDEFReader();
167+
await ndef.scan({ signal: abortController.signal });
163168

164-
navigator.nfc.ndef.write("foo", { signal: abortController.signal });
169+
await ndef.push("foo", { signal: abortController.signal });
165170

166171
document.querySelector("#abortButton").onclick = event => {
167172
abortController.abort();
@@ -217,19 +222,17 @@ object/namespace, like Web Bluetooth, Web USB, etc. Unlike these APIs, the newer
217222
Generic Sensor APIs don’t attach themselves to the navigator object/namespace
218223
and have separate and dedicated objects like Accelerometer, Gyroscope, etc.
219224

220-
The newer pattern allows node.js to implement the
225+
We decided to follow this newer pattern as it allows node.js to implement the
221226
same API, and have it loaded as a separate module. People working on Web
222227
Assembly are also advocating for this patterns as it might be able to turn such
223228
globals into modules in the future, at least when accessed from WASM.
224229

225-
However, since Web NFC is close to Web Bluetooth and Web USB, and because scan
226-
filters were abandoned after Origin Trials feedback, attaching to the navigator
227-
object seemed to be a proper alignment.
228-
229230
### Separate objects for reader/writer
230231

231-
The reader and writer objects existed separately when scan filters were supported,
232-
but after filters have been abandoned, they have been merged into one single object.
232+
The reader and writer objects could have been merged into one single object, but
233+
as we allow multiple scans with filters to be active at the same time (maybe in
234+
multiple places/view of the app/site) then it makes more sense to be able to use
235+
separate objects.
233236

234237
## Considered alternatives
235238

0 commit comments

Comments
 (0)