Skip to content

Commit e8c628e

Browse files
authored
fix: bail early if no printers on the network (electron#22418)
1 parent efc1156 commit e8c628e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

docs/api/web-contents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ Returns [`PrinterInfo[]`](structures/printer-info.md)
12861286
`A4`, `A5`, `Legal`, `Letter`, `Tabloid` or an Object containing `height`.
12871287
* `callback` Function (optional)
12881288
* `success` Boolean - Indicates success of the print call.
1289-
* `failureReason` String - Called back if the print fails; can be `cancelled` or `failed`.
1289+
* `failureReason` String - Error description called back if the print fails.
12901290

12911291
Prints window's web page. When `silent` is set to `true`, Electron will pick
12921292
the system's default printer if `deviceName` is empty and the default settings for printing.

shell/browser/api/electron_api_web_contents.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,14 @@ void WebContents::OnGetDefaultPrinter(
17661766

17671767
base::string16 printer_name =
17681768
device_name.empty() ? default_printer : device_name;
1769+
1770+
// If there are no valid printers available on the network, we bail.
1771+
if (printer_name.empty() || !IsDeviceNameValid(printer_name)) {
1772+
if (print_callback)
1773+
std::move(print_callback).Run(false, "no valid printers available");
1774+
return;
1775+
}
1776+
17691777
print_settings.SetStringKey(printing::kSettingDeviceName, printer_name);
17701778

17711779
auto* print_view_manager =

0 commit comments

Comments
 (0)