Search for Printer
Use StarDeviceDiscoveryManager to search for the printer and obtain permission to connect.
When you execute a search, you can acquire the StarPrinter instance.
Memo
The StarPrinter instance provides the functions required to communicate with the printer.
There are two methods, including searching, to acquire the StarPrinter instance.
- Method to acquire by searching (Step 4 on this page)
- Method to generate by passing interfaceType and identifier to the constructor of the StarPrinter class
By using this StarPrinter instance, you can send printing data to the printer and control POS peripheral devices.
Search for the printer using the procedure below.
The sample code is available at the bottom of the page.
Also, refer to the sample application in the SDK.
1 Create a StarDeviceDiscoveryManager type instance used for searching.
Specify the type of printer interface to search for.
const discoveryManager = new StarDeviceDiscoveryManager(InterfaceType.Usb);
2 Implement the process for when the printer is found. Set the delegate method for when the printer is found in the onPrinterFound property.
discoveryManager.onPrinterFound = async (printer: StarPrinter) => {
console.log(`Found printer: ${printer.connectionSettings.identifier}.`);
};
3 Call the discover method to execute the search.
await discoveryManager.discover();
4 Implement the process for when an error occurs. You can identify the error cause based on the error instance type.
Possible errors are described in the API reference of the discover method of the StarDeviceDiscoveryManager class.
try{
...
} catch(error) {
console.log(`Error: ${String(error)}`);
};
Sample code
private discovery = async() => {
try {
const discoveryManager = new StarDeviceDiscoveryManager(InterfaceType.Usb);
discoveryManager.onPrinterFound = async (printer: StarPrinter) => {
console.log(`Found printer: ${printer.connectionSettings.identifier}.`);
};
await discoveryManager.discover();
} catch (error) {
console.log(`Error: ${String(error)}`);
}
};
Obtain permission to connect
The WebUSB API specification requires you to obtain permission to connect to the printer before starting communication.
Executing a search using StarDeviceDiscoveryManager.discover() searches for the printer and obtains permission to connect.
The following operations may require you to obtain permission to connect again:
- Clearing the browser cache
- Clearing the browser cache
- Restarting the browser
- Restarting the host device
- Removing and reinserting the USB cable
- Turning off and back on the printer
Memo
Obtaining permission to connect using StarDeviceDiscoveryManager is not necessary if permission is granted in advance through Google Enterprise.
For details, refer to Google Enterprise and Education Help.

