Download the PHP package sghimire/mobile-browser without Composer

On this page you can find all versions of the php package sghimire/mobile-browser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mobile-browser

Mobile Browser

Native in-app browsing for NativePHP Mobile apps, powered by android.webkit.WebView on Android and WKWebView on iOS — with a one-line escape hatch to hand a URL off to the device's external default browser instead, and a proper native OAuth flow for signing in with a third-party provider.

This package is a free, self-contained plugin. It ships its own Laravel facade, fluent builders, Laravel events, JS/TypeScript bindings, and the native Kotlin/Swift implementation — no paid plugin dependency.

Features

Example App

Authenticator is a full example app built using this plugin

Requirements

Installation

Laravel's package auto-discovery registers BrowserServiceProvider for you. Then register the plugin with NativePHP:

This wires up the plugin's nativephp.json manifest (bridge functions, Android INTERNET permission) into your native build. Rebuild/reinstall the native shell afterwards (php artisan native:install or native:run) so it's picked up.

How It Works (Under the Hood)

Same two-phase pattern as every async call in this plugin family — a synchronous "start" acknowledgement, then the real result delivered later through two parallel channels.

  1. Request out. Browser::open($url)->open() (PHP) and Browser.open(url) (JS) both reach the same bridge — JS via fetch('/_native/api/call', { method: 'MobileBrowser.Open', params }), PHP via nativephp_call('MobileBrowser.Open', json_encode($params)). The bridge router matches "MobileBrowser.Open" to BrowserFunctions.Open.
  2. Immediate ack. The call returns right away confirming the request was accepted — not that the page has loaded (webview mode) or that the external browser actually opened.
  3. Result comes back later, twice. In webview mode, once the page finishes its first load, the native side injects a native-event CustomEvent on document (what the JS On()/Off() helpers listen for) and makes a call back into Laravel that dispatches the real Opened event (what Event::listen() / #[OnNative] pick up). Closing the browser delivers Closed the same way. In external mode, Opened fires as soon as the OS confirms the hand-off succeeded; a failed hand-off (no browser available, bad URL) is returned as a synchronous bridge error instead.
  4. Because results are asynchronous and delivered to PHP and JS independently, always drive your UI from the Opened / Closed events — never from the return value of open().
  5. Browser::auth($authorizeUrl, $redirectUri)->auth() follows the identical two-phase pattern over MobileBrowser.Auth / BrowserFunctions.Auth: an immediate ack that the sign-in was presented, followed later by AuthCompleted (the callback URL arrived) or Closed (cancelled or failed).

In-app browser UI

The webview mode overlay uses a compact, modern header — the same shape as Instagram's or Chrome Custom Tabs' in-app browser, not a full custom chrome — and it's the same on both platforms:

showToolbar(false) hides this header entirely, leaving a bare webview (e.g. a kiosk-style page). showNavigationButtons(false) changes what a tap on the header's back button does — it stops walking page history and just closes the overlay instead; it has no effect on the hardware/gesture back, which always tries page history first either way.

There's no separate back/forward/reload bar anymore — reload moved into the overflow menu, and forward navigation was dropped in favor of this simpler, single-header layout.


PHP Usage

The Browser facade

open() on the builder returns bool — true once the request reached the native bridge, false if it couldn't be started (e.g. running outside the native shell, or the builder was already opened once).

If you never call ->open() explicitly, it fires automatically when the builder object is destructed. Calling ->open() yourself is recommended so you can check the return value.

Builder methods

Method Description
mode(string $mode) 'webview' (default) or 'external'. Throws InvalidArgumentException if unknown.
external(bool $external = true) Shortcut for mode('external') / mode('webview').
title(string $title) Subtitle shown under the page's own title in the header, webview mode. Header shows just the page title if you don't set this.
showToolbar(bool $enabled = true) Show/hide the compact header (back button, title, overflow menu) in webview mode.
showNavigationButtons(bool $enabled = true) Whether tapping the header's back button can walk the page's own navigation history before closing the overlay. Hardware/gesture back is unaffected.
shareButton(bool $enabled = true) Show/hide "Share…" in the header's overflow menu.
desktopMode(bool $enabled = true) Request a desktop user agent instead of the mobile one. webview mode only.
id(string $id) Custom correlation ID for this session (not auto-generated — null unless set).
getId() Get this session's correlation ID, or null.
open() Send the open request to the native bridge. Returns bool.

Supported modes

webview, external (also available as PendingOpen::MODES). Defaults to webview if mode() / external() is never called.

Closing an in-app browser

Useful for dismissing an open webview session programmatically (e.g. from elsewhere in the UI once a task completes):

This fires Closed with reason: 'closed_by_app'. It has no effect on a URL opened with external(), since that leaves your app entirely. Browser::close() also cancels an in-progress auth() sign-in — see below.

OAuth sign-in with auth()

open() is deliberately not meant for logging a user into a third-party provider — most providers (Google included) detect and reject sign-in attempts from an embedded WebView ("Error 403: disallowed_useragent"), and even where it's not blocked outright, an app-controlled WebView can read the password field, which is exactly what OAuth exists to avoid. auth() runs the authorization-code flow in a proper isolated system browser context instead:

The two arguments are Browser::auth(string $authorizeUrl, string $redirectUri):

Builder methods

Method Description
ephemeral(bool $enabled = true) Use a private browsing session with no shared cookies/SSO state, so the provider always shows a fresh login instead of silently reusing a previous session. Defaults to true. On iOS this maps directly to prefersEphemeralWebBrowserSession; Android's CookieManager has no per-session scoping, so this clears the app's WebView cookie jar before presenting the Custom Tab instead — see the platform notes below.
id(string $id) Custom correlation ID for this session.
getId() Read the current correlation ID, or null.
auth() Send the request to the native bridge. Returns bool.

If you never call ->auth() explicitly, it fires automatically when the builder object is destructed, same as open().

Handling the result

$event->params already has both grant types covered: authorization-code flows return code/state as query parameters, implicit-grant flows return access_token/token_type/etc. in the URL fragment — both are parsed into the same flat array.

Cancel a sign-in in progress the same way you'd close a browser session:

Listening for results

Livewire: #[OnNative]


JavaScript Usage

Importing

This package doesn't publish a #nativephp import alias (that's reserved for NativePHP's first-party plugins). Import the file directly — either from the vendor path, or copy it into your own resources/js/ and import it from there:

Full TypeScript types (including the BrowserMode union) are included in browser.d.ts alongside it.

Basic open

Browser.open(url) returns a thenable builder — await it directly, or chain builder methods first:

Closing an in-app browser

OAuth sign-in

Browser.auth(authorizeUrl, redirectUri) runs the same native OAuth flow as the PHP auth() builder (see the PHP section above for the full explanation of why this exists instead of just using open(), and why redirectUri must use the nativephp:// scheme):

Listening for events

React example

JS API reference

Export Signature Description
Browser.open(url) (string) => PendingOpen Start building an open request.
.mode(mode) (BrowserMode) => this 'webview' or 'external'. Throws if unknown.
.external(external?) (boolean = true) => this Shortcut for mode('external') / mode('webview').
.title(title) (string) => this Subtitle shown under the page's own title in the header, webview mode only.
.showToolbar(enabled?) (boolean = true) => this Show/hide the compact header (back button, title, overflow menu).
.showNavigationButtons(enabled?) (boolean = true) => this Whether the header's back button can walk page history before closing the overlay. Hardware/gesture back is unaffected.
.shareButton(enabled?) (boolean = true) => this Show/hide "Share…" in the header's overflow menu.
.desktopMode(enabled?) (boolean = true) => this Request a desktop user agent. webview mode only.
.id(id) (string) => this Custom correlation ID.
.getId() () => string \| null Read the current correlation ID.
Browser.auth(url, redirectUri) (string, string) => PendingAuth Start building an OAuth sign-in request. redirectUri must use the nativephp:// scheme.
.ephemeral(enabled?) (boolean = true) => this Use a private session with no shared cookies/SSO state. Defaults to true.
Browser.close(id?) (string?) => Promise<{ closed: boolean }> Dismiss the open in-app browser, or cancel an in-progress auth() sign-in.
On(event, callback) (string, (payload, eventName) => void) => void Subscribe to a native event.
Off(event, callback) (string, (payload, eventName) => void) => void Unsubscribe.
Events.Browser.Opened string Event name constant.
Events.Browser.Closed string Event name constant.
Events.Browser.AuthCompleted string Event name constant.

await-ing (or .then-ing) a PendingOpen/PendingAuth sends the request to the native bridge exactly once — awaiting it twice is a no-op the second time.


Events reference

Opened

Dispatched once the page has loaded (webview mode) or the OS confirms the hand-off succeeded (external mode).

Property Type Description
url string / string The URL that was opened.
mode string / 'webview' \| 'external' Which mode served the request.
id ?string / string \| null The correlation ID from .id(), if one was set.

Closed

Dispatched when the in-app browser is dismissed, when an external hand-off fails, or when an auth() sign-in ends without completing.

Property Type Description
reason ?string / string \| null Browsing: "user_closed", "closed_by_app", "replaced", "load_error", "invalid_url", "no_browser_available", "launch_failed". Sign-in: "user_cancelled", "closed_by_app", "replaced", "auth_failed", "no_browser_available", "invalid_url". Never null in practice.
id ?string / string \| null The correlation ID from .id(), if one was set.

AuthCompleted

Dispatched once the OAuth provider redirects back to redirectUri after auth().

Property Type Description
callbackUrl string / string The full callback URL exactly as the provider sent it.
params array / Record<string, string> Every query and URL-fragment parameter, already parsed and merged into one flat map — covers both authorization-code (code, state) and implicit-grant (access_token, token_type, ...) flows.
id ?string / string \| null The correlation ID from .id(), if one was set.

Platform notes

Android iOS
Min OS version API 23 15.0
Permission android.permission.INTERNET none
Native implementation resources/android/BrowserFunctions.kt (android.webkit.WebView) resources/ios/BrowserFunctions.swift (WKWebView)
External hand-off Intent.ACTION_VIEW UIApplication.shared.open
OAuth sign-in Chrome Custom Tabs (androidx.browser:browser) + a dedicated BrowserAuthActivity that owns the nativephp:// intent-filter ASWebAuthenticationSession

Both are configured automatically by nativephp.json — you don't need to edit native project files by hand.

OAuth implementation notes and known limitations

Testing

Outside of a compiled native shell, Browser::open($url)->open() and Browser::close() return false (there's no bridge to call) — this is expected and is exactly what the test suite asserts.

License

MIT


All versions of mobile-browser with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
nativephp/mobile Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sghimire/mobile-browser contains the following files

Loading the files please wait ...