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

fix: bail early if no printers on the network #22517

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/web-contents.md
Expand Up @@ -1264,7 +1264,7 @@ Returns [`PrinterInfo[]`](structures/printer-info.md)
* `vertical` Number (optional) - The vertical dpi.
* `callback` Function (optional)
* `success` Boolean - Indicates success of the print call.
* `failureReason` String - Called back if the print fails; can be `cancelled` or `failed`.
* `failureReason` String - Error description called back if the print fails.

Prints window's web page. When `silent` is set to `true`, Electron will pick
the system's default printer if `deviceName` is empty and the default settings for printing.
Expand Down
8 changes: 8 additions & 0 deletions shell/browser/api/atom_api_web_contents.cc
Expand Up @@ -1679,6 +1679,14 @@ void WebContents::OnGetDefaultPrinter(
base::string16 default_printer) {
base::string16 printer_name =
device_name.empty() ? default_printer : device_name;

// If there are no valid printers available on the network, we bail.
if (printer_name.empty() || !IsDeviceNameValid(printer_name)) {
if (print_callback)
std::move(print_callback).Run(false, "no valid printers available");
return;
}

print_settings.SetStringKey(printing::kSettingDeviceName, printer_name);

auto* print_view_manager =
Expand Down