New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the correct way to check whether the browser supports Web NFC API or not? #434
Comments
Are there NFC chips that support only reading, but not writing NFC tags? If yes, how to detect this? |
Indeed! if ('NDEFReader' in window) { /* ... Scan NDEF Tags */ }
if ('NDEFWriter' in window) { /* ... Write NDEF Tags */ } You can also use Permissions API try {
const status = await navigator.permissions.query({ name: 'nfc'});
}
catch(e) {
// No Web NFC support
} |
To check whether the device has NFC chip or not, you can call |
I don't think so. |
@beaufortfrancois What about adding this to the spec? |
Which parts? Good luck for your talk by the way ;) |
Thanks! This is workshop, not talk. :)
About browser feature detection: #434 (comment). |
I'll do this. |
I know. :) Thanks! |
Cool! |
@beaufortfrancois Just curious, what if I call |
navigator.permissions.query({ name: "nfc" }).then(permissionStatus => {
console.log(`NFC user permission: ${permissionStatus.state}`);
permissionStatus.onchange = _ => {
console.log(`NFC user permission changed: ${permissionStatus.state}`);
};
}); |
https://w3c.github.io/web-nfc/#feature-support has been added to the spec. |
Silently? It would be great to let the user know what went wrong and provide the ability to enable NFC in the OS settings (see screenshots in #434 (comment)). P.S. Sorry for offtopic. |
Having something similar to Geolocation makes sense to me. |
Just to clarify, will there be a separate permission prompt for writing NFC (alongside permission prompt for reading NFC) or one single permission prompt for the whole Web NFC API (both reading and writing)? Use case: what if I want to allow the web app to only read NFC tags but not write? I'm not familiar with the process of merge code in Chromium. I see that the NFC permission change was merged, but I've just tested in Chrome Canary for Android with |
In Chromium, there will be one single permission prompt for using the Web NFC API.
I'm currently working on making sure tests pass for https://chromium-review.googlesource.com/c/chromium/src/+/1895345. Once it's solved, it will be pushed to Chromium. I hope this will be done this week or next week. |
Any plans to separate permission prompts for reading and writing? From the name of https://chromium-review.googlesource.com/c/chromium/src/+/1895345 — What if I try to read NFC tags (if user didn't previously allow Web NFC), will the permission prompt be shown? |
Nope. Not in Chromium.
Yup. Once user approves Web NFC, prompt won't be shown anymore. |
For info, I'm currently adding "second" prompt to Chrome to turn on NFC if needed. See https://chromium-review.googlesource.com/c/chromium/src/+/1940241 |
@FluorescentHallucinogen All bits have finally landed in Chrome Canary for Android. You can give it a try at https://permission.site |
@beaufortfrancois That's awesome! Thanks for your work! One detail: what about changing the word "phone" in texts to more generic "device"? What if my device is e.g. tablet, not phone? |
@FluorescentHallucinogen I'll share this feedback with the team. Thanks! |
@beaufortfrancois Any plans on Origin Trial for Web NFC API? |
@FluorescentHallucinogen : We are planning for M81, so around end of Jan '20. |
To know more about the Origin Trial for Web NFC, I'd recommend having a look at https://web.dev/nfc/ |
What is the correct way to check whether the browser supports Web NFC API or not?
In the previous version of API, I've used the following:
Is
the correct way?
It would also really nice to have a property (or something) to check whether the device has NFC chip or not.
The text was updated successfully, but these errors were encountered: