Serial, USB, NFC and even local Files with Chrome's new APIs.

Share your advanced knowledge/code with the community.
Ungaretti
Posts: 1
Joined: Sun Jul 18, 2021 8:17 pm

Serial, USB, NFC and even local Files with Chrome's new APIs.

Post by Ungaretti »

Hi everyone!
I'm not a professional programmer, but I was well aware that browsers do not interact with client's hardware, like serial ports, USB or local file system, so I was stunned to find out that Chrome now has APIs that brake that barrier: https://web.dev/fugu-status/ .
It needs Chrome 89 or newer. Aparently it also works with Edge, but not with Firefox, Opera or Safari .

I made a simple test to locate a connected serial port and it really works :

Code: Select all

  Procedure ButtonHandler()
    Debug "Button click event on gadget #" + EventGadget()
    !navigator.serial.requestPort()
  EndProcedure
  
  OpenWindow(0, 100, 100, 200, 50, "Click test", #PB_Window_SystemMenu)
    ButtonGadget(0, 10, 10, 180, 30, "Click me")
  
  BindGadgetEvent(0, @ButtonHandler())
I think that creating a hardware library with those APis would be a fantastic improvement to Spiderbasic!
I apologize if all this is yesterday's news, but, like I said, I'm not a programmer and I was really surprised.

Edit#1: - Forgot to mention that you have to create an app and open it with Chrome, of course. Spiderbasic's browser does not have those APIs.

// Moved to "Tricks 'n' Tips" (Peter)
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Serial, USB, NFC and even local Files with Chrome's new APIs.

Post by Peter »

Ungaretti wrote: Sun Jul 18, 2021 9:02 pmSpiderbasic's browser does not have those APIs.
There is no "SpiderBasic-Browser".
SpiderBasic opens the standard browser by pressing the <F5> key (unless otherwise specified in the preferences).
If you have set Chrome as your default browser, it should also open when you start a SpiderBasic code.
Post Reply