Skip to content
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

Can I use it in chrome extension? #118

Closed
bryht opened this issue Nov 2, 2021 · 2 comments
Closed

Can I use it in chrome extension? #118

bryht opened this issue Nov 2, 2021 · 2 comments

Comments

@bryht
Copy link

bryht commented Nov 2, 2021

Anyone knowing about the question? want to add NFC read ability to my website. Or anyone has other ideas? Thanks in advance.

@pokusew
Copy link
Owner

pokusew commented Nov 2, 2021

Hi @bryht,

unfortunately, nfc-pcsc cannot be used in Chrome extensions. 😢 nfc-pcsc can be only in Node.js environments because it uses Node Native Modules to access system PC/SC API. So the Node.js runtime and PC/SC API are required for nfc-pcsc to run. That makes it possible to use it on most OS (Windows, macOS, Linux) directly in Node.js or in Electron.js and desktop apps.

Depending on your use case, there are different possibilities for the use of NFC in the browsers (whether directly in web pages/apps or in browser extensions):

  • Web NFC API – experimental web standard, only works in Chrome 89+ on Android, works with built-in NFC readers, only supports NDEF formatted tags, see web.dev/nfc.
  • Web USB API – experimental web standard, usable, allows accessing USB devices. You can implement support for your USB NFC reader. You can try this fork of chrome-nfc, which uses Web USB and supports quite common reader ACR122U. UPDATE: I tried the demo myself today and it did not work out of the box (at least not on macOS). Unfortunately, Web USB blocks access to some classes of USB interfaces ("protected classes"), one of which is the Smart Cards interface (NFC). Maybe it can be somehow overcome (changing the system USB drivers' config so that the device has a different class assigned).
  • chrome.usb – that's an API only available in the deprecated Chrome Apps platform. It is similar to the Web USB but it does not prevent access to the protected classes. It is used by the original chrome-nfc demo app. I remember I got it working once, but now it seems that it does not work. Anyway, it is not worth considering this option, as Chrome Apps (and thus chrome.usb) are deprecated and their implementation will be soon removed from Chrome.
  • Web HID API, Web Serial API – depending on your reader, you could implement communication using these experimental web standards.
  • Browser web app communicating via WebSocket with a Node.js server (on localhost) running nfc-pcsc – that's perfectly doable, and you have complete control over the NFC implementation if you are okay with running a background Node.js app. But maybe, in that case, you could ship your product directly as a desktop app based on Electron.js (which is supported by nfc-pcsc).

Hope this answers your question. 🙂 Let me know if you need anything else.

@bryht
Copy link
Author

bryht commented Nov 3, 2021

Hi @pokusew,

Thank you for the detail answers, they are really helpful, follow your advice, I have tried Web HID API and Web Serial API in chrome console:
await navigator.hid.requestDevice({filters:[]})
await navigator.serial.requestPort()

unfortunately they cannot list my ACR122U,
image
but I will try more, hopefully will get some result.

@bryht bryht closed this as completed Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants