files/en-us/web/api/ndefreader/scan/index.md
{{SecureContext_Header}}{{SeeCompatTable}}{{APIRef("Web NFC API")}}
The scan() method of the {{DOMxRef("NDEFReader")}} interface activates a reading device and returns a {{jsxref("Promise")}} that either resolves when an NFC tag read operation is scheduled or rejects if a hardware or permission error is encountered. This method triggers a permission prompt if the "nfc" permission has not been previously granted.
scan(options)
options {{optional_inline}}
signal
scan() operation.A {{JSxRef("Promise")}} that resolves immediately after scheduling read operations for the NFC adapter.
This method doesn't throw exceptions; instead, it rejects the returned promise,
passing a {{domxref("DOMException")}} whose name is one of the
following:
AbortError {{domxref("DOMException")}}
options argument.InvalidStateError {{domxref("DOMException")}}
NotAllowedError {{domxref("DOMException")}}
NotSupportedError {{domxref("DOMException")}}
This example shows what happens when a scan promise rejects and readingerror is thrown.
const ndef = new NDEFReader();
ndef
.scan()
.then(() => {
console.log("Scan started successfully.");
ndef.onreadingerror = (event) => {
console.log(
"Error! Cannot read data from the NFC tag. Try a different one?",
);
};
ndef.onreading = (event) => {
console.log("NDEF message read.");
};
})
.catch((error) => {
console.log(`Error! Scan failed to start: ${error}.`);
});
{{Specifications}}
{{Compat}}