---
title: "JavaScript Adapter"
description: "@laravel-rust-mobile/core lets your Inertia pages call native features such as haptics, Face ID, sharing, and notifications, while the same pages keep working in a browser."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.lairport.app/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript Adapter

## Introduction

The `@laravel-rust-mobile/core` package lets your Inertia pages call native features, such as haptics or Face ID. Inside your iOS or Android app, each call uses the device. In a browser, or during server-side rendering, it does nothing or uses the matching web API, so the very same page works everywhere:

```ts
import { mobile } from '@laravel-rust-mobile/core';

await mobile.haptics.success();

if (await mobile.biometrics.authenticate('Unlock your wallet')) {
    router.visit('/wallet');
}
```

> **Early release**
>
> Lairport is at v0.1. The `laravel-mobile` CLI is published on crates.io, and the `@laravel-rust-mobile/core` adapter is published on npm. Each feature is in beta or alpha: beta features are ready to try on your own apps, and alpha features are experimental. The [status](https://docs.lairport.app/status/) page lists the stage of each feature.

## Installation

If you created your mobile app with `laravel-mobile init`, the package is already in your `package.json` file and installed. Otherwise, install it with npm:

```sh
npm install @laravel-rust-mobile/core
```

The package has no dependencies of its own. React and Vue are optional peer dependencies, so you only need the framework your app already uses.

> **Note**
>
> If you're using `laravel-mobile-cli` 0.1.0, the agent skill that `init` installs still mentions the package's earlier name, `@laravel-rust/mobile`. The package you want is `@laravel-rust-mobile/core`.

Each feature also needs its plugin enabled in `mobile.toml`. For example, to use haptics and Face ID:

```toml title="mobile.toml"
[plugins]
haptics = true
biometric = true

[permissions]
biometrics = "Unlock your wallet with Face ID."
```

## Using It in Components

In React or Vue components, you may use the `useMobile` hook:

```tsx
import { useMobile } from '@laravel-rust-mobile/core/react';

export default function SaveButton() {
    const mobile = useMobile();

    return <button onClick={() => mobile.haptics.success()}>Save</button>;
}
```

For Vue, import `useMobile` from `@laravel-rust-mobile/core/vue` instead.

## Available Methods

| Method | In your app | In a browser |
| --- | --- | --- |
| `mobile.isNative()` | `true` | `false` |
| `mobile.platform()` | `'ios'` or `'android'` | `'web'` |
| `mobile.haptics.impact(style?)`, `.success()`, `.warning()`, `.error()`, `.selection()`, `.vibrate(ms)` | Haptic feedback. Needs `haptics = true`. | Does nothing. |
| `mobile.biometrics.available()` | Whether Face ID, Touch ID, or fingerprint unlock is set up. | `false` |
| `mobile.biometrics.authenticate(reason, options?)` | `true` once the user confirms, `false` if they cancel. The `options` object takes a `title`, which titles the Android prompt and defaults to "Verify it's you". Needs `biometric = true` and `permissions.biometrics`. | `false` |
| `mobile.storage.get(key, fallback?)`, `.put(key, value)`, `.has(key)`, `.forget(key)` | Small JSON values kept on the device between launches, like Laravel's cache. Not for secrets. Needs `store = true`. | `localStorage`. |
| `mobile.clipboard.copy(text)`, `.read()` | The system clipboard. Needs `clipboard-manager = true`. | The browser's clipboard, or `false` and `null`. |
| `mobile.location.current()` | `{ latitude, longitude, accuracy }`, after asking the user; `null` if they say no. Needs `geolocation = true` and `permissions.location`. | The browser's location, or `null`. |
| `mobile.scanner.scan(options?)`, `.cancel()` | The first barcode or QR code the camera reads. It asks for camera access first, and resolves `null` when the user cancels or refuses. It scans behind the page by default (`windowed: true`), so the page needs a transparent background and a Cancel button. Needs `barcode-scanner = true` and `permissions.camera`. | `null`. |
| `mobile.network.online()`, `.onChange(callback)` | Whether the device is online, and a listener for changes that returns a function to stop it. | The same. |
| `mobile.share({ title, text, url })` | The share sheet, where the WebView supports it. | The browser's share sheet, or `false`. |
| `mobile.notifications.requestPermission()`, `.granted()`, `.send(title, { body })` | Local notifications. Needs `notification = true` and `permissions.notifications`. | Web notifications. |
| `mobile.invoke(command, args?)` | Calls a command you register with `tauri::generate_handler!` in `apps/mobile/src/lib.rs`. `sync` grants your pages access to it. | Throws, so check `mobile.isNative()` first. |

Android's WebView doesn't have a share sheet yet, so `mobile.share` resolves `false` there. When it does, you may fall back to copying the link.

## Branching on the Platform

Most of the time, you can call these methods without checking where your page is running. When the experience genuinely needs to differ, you may branch on `mobile.isNative()`:

```ts
if (mobile.isNative()) {
    await mobile.invoke('export_to_files', { id: report.id });
} else {
    window.location.href = `/reports/${report.id}/download`;
}
```

## Calling a Plugin You Haven't Enabled

If you call a feature whose plugin isn't enabled, the call throws an error that names the `[plugins]` line to add to `mobile.toml`. Add it, run `laravel-mobile sync`, and rebuild the app.

The network calls use the browser's own events, so they need no plugin.

## Full-Height Sections on Android

On Android, the page shrinks when the keyboard opens, so it stays above the keyboard. `100vh` and `100dvh` shrink with it. For a section that should keep the full screen height, use `100lvh` instead.

Source: https://docs.lairport.app/js-adapter/index.mdx
