files/en-us/web/api/serialport/getinfo/index.md
{{SecureContext_Header}}{{APIRef("Web Serial API")}}{{SeeCompatTable}}{{AvailableInWorkers("window_and_dedicated")}}
The getInfo() method of the {{domxref("SerialPort")}} interface returns an object containing identifying information for the device available via the port.
getInfo()
None.
An object containing the following properties:
usbVendorId
undefined.usbProductId
undefined.bluetoothServiceClassId {{experimental_inline}}
undefined.This snippet calls the {{domxref("Serial.requestPort()")}} method when a <button> is pressed. We pass a filter to requestPort() to filter for Arduino Uno USB devices. Once a port is requested, we call getInfo() to return the device's usbProductId and usbVendorId.
<button id="connect">Connect</button>
const connectBtn = document.getElementById("connect");
// Filter for devices with the Arduino Uno USB Vendor/Product IDs
const filters = [
{ usbVendorId: 0x2341, usbProductId: 0x0043 },
{ usbVendorId: 0x2341, usbProductId: 0x0001 }
];
connectBtn.addEventListener("click", () => {
try {
// Prompt the user to select an Arduino Uno device
const port = await navigator.serial.requestPort({ filters });
// Return the device's identifying info
const { usbProductId, usbVendorId } = port.getInfo();
} catch (e) {
// The user didn't select a device
}
});
{{Specifications}}
{{Compat}}