Class Navigator

The Navigator interface represents the state and the identity of the user agent. It allows scripts to query it and to register themselves to carry on some activities.

A Navigator instance can be retrieved by accessing the global navigator property.

Accessors

Methods

  • Returns an array of Gamepad objects, one for each gamepad connected to the device.

    The indexes of the gamepads array map to the paired controller numbers assigned by the system. Index 0 is the first controller, index 1 is the second controller, and so on.

    Index 0 is a special case, which represents input from both the first controller as well as the handheld mode controller.

    The gamepads array contains 8 entries, so up to 8 controllers can be connected to the device at a time. Disconnected controllers will have null values in the array.

    Returns (null | Gamepad)[]

    Example

    if (navigator.getGamepads()[0].buttons[0].pressed) {
    console.log('Button B is pressed on the first controller');
    }

    See

    https://developer.mozilla.org/docs/Web/API/Navigator/getGamepads

  • Vibrates the main gamepad for the specified number of milliseconds or pattern.

    If a vibration pattern is already in progress when this method is called, the previous pattern is halted and the new one begins instead.

    Parameters

    • pattern: number | Vibration | (number | Vibration)[]

      Provides a pattern of vibration and pause intervals. Each value indicates a number of milliseconds to vibrate or pause, in alternation. You may provide either a single value (to vibrate once for that many milliseconds) or an array of values to alternately vibrate, pause, then vibrate again.

    Returns boolean

    Example

    // Vibrate for 200ms with the default amplitude/frequency values
    navigator.vibrate(200);

    // Vibrate 'SOS' in Morse Code
    navigator.vibrate([
    100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30, 100,
    ]);

    // Specify amplitude/frequency values for the vibration
    navigator.vibrate({
    duration: 500,
    lowAmp: 0.2
    lowFreq: 160,
    highAmp: 0.6,
    highFreq: 500
    });

    See

    https://developer.mozilla.org/docs/Web/API/Navigator/vibrate