1. API
  2. webContents

API

Functions

Function Description
availablePrinters() Get a list of all available printers on the user's system.
canGoBack() Determine if the history stack has items before the currently loaded URL.
canGoForward() Determine if the history stack has items ahead of the currently loaded URL.
getZoomFactor()
getZoomLevel()
loadURL({ ref }, args) Loads a URL into the WebContents
openUrlInApp(url) Explicitly open a specified URL within the desktop app. This bypasses the check and always opens URL in-app and never in the system browser.
print(options) Adds a print job for the current page to the operating system's queue for immediate printing.
setZoomFactor(factor)
setZoomLevel(level)
toggleDevTools() Toggles whether developer tools are displayed in the current WebContents.

availablePrinters()

Get a list of all available printers on the user's system.

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.availablePrinters(): Promise<Printer[]>;

      

Returns:

Promise<Printer[]>

Example

        import { printing } from "@todesktop/client";

async function logPrinters() {
  const printers = await printing.availablePrinters();
}


      

canGoBack()

Determine if the history stack has items before the currently loaded URL.

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.canGoBack(): Promise<boolean>;

      

Returns:

Promise<boolean>

canGoForward()

Determine if the history stack has items ahead of the currently loaded URL.

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.canGoForward(): Promise<boolean>;

      

Returns:

Promise<boolean>

getZoomFactor()

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.getZoomFactor(): Promise<number>;

      

Returns:

Promise<number>

The current zoom factor

getZoomLevel()

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.getZoomLevel(): Promise<number>;

      

Returns:

Promise<number>

The current zoom level

loadURL()

Loads a URL into the WebContents

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.loadURL({ ref }: {
    ref?: Ref;
}, ...args: Parameters<WebContents["loadURL"]>): Promise<void>;

      
Parameters
Parameter Type Description
{ ref } { ref?: Ref; }
args Parameters&lt;WebContents["loadURL"]>

Returns:

Promise<void>

openUrlInApp()

Explicitly open a specified URL within the desktop app. This bypasses the check and always opens URL in-app and never in the system browser.

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.openUrlInApp(url: string): Promise<void>;

      
Parameters
Parameter Type Description
url string URL to open. Example: 'https://www.google.com'

Returns:

Promise<void>

print()

Adds a print job for the current page to the operating system's queue for immediate printing.

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.print(options: PrintJob): Promise<PrintJob>;

      
Parameters
Parameter Type Description
options PrintJob Options to use when processing this print job.

Returns:

Promise<PrintJob>

setZoomFactor()

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.setZoomFactor(factor: number): Promise<void>;

      
Parameters
Parameter Type Description
factor number

Returns:

Promise<void>

setZoomLevel()

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.setZoomLevel(level: number): Promise<void>;

      
Parameters
Parameter Type Description
level number The zoom level to set the current WebContents to.

Returns:

Promise<void>

toggleDevTools()

Toggles whether developer tools are displayed in the current WebContents.

Signature:

        import { webContents } from "@todesktop/client-core"
webContents.toggleDevTools(): Promise<void>;

      

Returns:

Promise<void>

Variables

Variable Description
on

on

Signature:

        on: (event: "*" | "navigate", callback: (...any: any[]) => void) => Promise<() => Promise<void>>

      

Type Aliases

Printer

A single printer.

Signature:

        export declare type Printer = {
    name: string;
    description: string;
    status: PrinterStatus;
    isDefault: boolean;
    options: {
        [key: string]: unknown;
    };
};

      

References: PrinterStatus

PrinterStatus

Represents the current status of a printer.

Signature:

        export declare type PrinterStatus = 
/**
 * The printer is online and awaiting jobs to process.
 * On Windows, this represents `PRINTER_STATUS_WAITING`.
 * On macOS and Linux, this represents CUPS status 3.
 */
"Idle"
/**
 * The printer is currently printing a document.
 * On Windows, this represents `PRINTER_STATUS_PRINTING`.
 * On macOS and Linux, this represents CUPS status 4.
 */
 | "Printing"
/**
 * The printer has stopped.
 * On Windows this represents `PRINTER_STATUS_PAUSED`.
 * On macOS and Linux, this represents CUPS status 5.
 */
 | "Stopped";

      

PrintJob

Configuration for a print job.

Signature:

        export declare type PrintJob = {
    silent?: boolean;
    printBackground?: boolean;
    deviceName: string;
};

      

WebContentsEvent

Signature:

        export declare type WebContentsEvent = "navigate";

      
Type Alias Description
Printer A single printer.
PrinterStatus Represents the current status of a printer.
PrintJob Configuration for a print job.
WebContentsEvent