Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pyxpo-web-browser

CI PyPI Python License: MIT

An in-app browser and OAuth sign-in sessions for pyxpo apps written in Python. The API follows expo-web-browser. iOS uses SFSafariViewController and ASWebAuthenticationSession. Android uses Chrome Custom Tabs (androidx.browser). The user keeps their cookies, saved passwords and autofill, and your app never sees them.

github.com open in the in-app browser, a Custom Tab on Android and Safari View Controller on iOS

import pyxpo_web_browser as WebBrowser

result = await WebBrowser.open_browser_async("https://pyxpo.dev", toolbar_color="#202020")

Features

  • In-app browser for any http or https page, with a colored toolbar.
  • OAuth sign-in: open_auth_session_async waits for the redirect and returns the final URL.
  • Presentation options: toolbar colors, share item, reader mode, bar collapsing, modal style.
  • Android Custom Tabs warm-up (warm_up_async, may_init_with_url_async) for faster first paint.
  • Works on the desktop by opening the system browser, so you can develop without a phone.
  • camelCase too: openBrowserAsync, toolbarColor=....

Contents

If you are... Start here
Opening a link Quick start
Styling the browser Options
Signing users in Sign-in
Speeding up the first load Warm-up
Exact names API reference · Errors
A real use Recipe: sign in with an OAuth provider
Stuck Testing · Troubleshooting · FAQ

Platform support

Target What works
Android, API 24+ Custom Tabs. open_browser_async returns {"type": "opened"} at once. Sign-in comes back as a deep link.
iOS 15+ SFSafariViewController and ASWebAuthenticationSession. The call resolves when the browser closes.
Desktop window and tests open_browser_async opens the system browser. open_auth_session_async raises NotSupportedError.
Web page Same as desktop.

Requires Python 3.9+ and pyxpo>=0.1.0a2.

Install

pip install pyxpo-web-browser
[tool.pyxpo]
scheme = "myapp"          # needed for sign-in redirects such as myapp://callback
modules = ["web-browser"]

Rebuild the app. There are no permissions and no Info.plist texts. The scheme is only needed if you use open_auth_session_async.

Quick start

from pyxpo import Button, Text, View, component, use_async, use_state
import pyxpo_web_browser as WebBrowser


@component
def Links():
    taps, set_taps = use_state(0)
    result, set_result = use_state(None)

    async def run():
        if taps > 0:
            set_result(await WebBrowser.open_browser_async(
                "https://github.com/pyxpo/pyxpo", toolbar_color="#1a73e8", controls_color="#ffffff"))

    use_async(run, [taps])

    return View(
        Button("Open pyxpo on GitHub", lambda: set_taps(taps + 1)),
        Text("result: %s" % (result,)),
    )

Tip: on iOS the awaited result arrives when the user closes the browser: {"type": "cancel"}. On Android it arrives immediately with {"type": "opened"}. Never use lambda: WebBrowser.open_browser_async(...) as a handler: the coroutine would not be awaited.

The in-app browser open on github.com, on Android and iOS

Result types

type Meaning
"opened" Android: the tab was opened. Desktop: the system browser was started.
"cancel" iOS: the user closed the browser. Sign-in: the user closed the page.
"dismiss" Your code called dismiss_browser() or dismiss_auth_session(). On Android sign-in it also means the user came back without finishing.
"locked" Another browser or session is already open.
"success" Sign-in only. result["url"] is the redirect URL including its query.

WebBrowserResultType has these values as an enum.

Options

Pass them as keyword arguments. camelCase names work too.

Option Platform Notes
toolbar_color both Any pyxpo color ("#202020", "orange").
secondary_toolbar_color Android
controls_color iOS Tint of the buttons.
enable_bar_collapsing both Hide the bar while scrolling.
show_title Android Show the page title.
enable_default_share_menu_item Android Add a Share item to the menu.
show_in_recents Android Keep the tab in the recent apps list (default off).
create_task Android Open the tab in its own task (default on).
browser_package Android Use this browser instead of the preferred one.
dismiss_button_style iOS "done", "close" or "cancel". Anything else raises ValueError.
reader_mode iOS Enter Reader when available.
presentation_style iOS A WebBrowserPresentationStyle: FULL_SCREEN, PAGE_SHEET, FORM_SHEET, CURRENT_CONTEXT, OVER_FULL_SCREEN (default), OVER_CURRENT_CONTEXT, POPOVER, AUTOMATIC.
prefer_ephemeral_session iOS, sign-in Share no cookies with Safari. This also skips the "wants to use ... to sign in" prompt.

Sign-in

from urllib.parse import parse_qs, urlparse

result = await WebBrowser.open_auth_session_async(
    "https://auth.example.com/authorize?client_id=abc&redirect_uri=myapp%3A%2F%2Fcallback",
    "myapp://callback",
    prefer_ephemeral_session=True,
)
if result["type"] == "success":
    code = parse_qs(urlparse(result["url"]).query)["code"][0]

redirect_url must start with the app's scheme. On iOS the system watches for the redirect. On Android, Custom Tabs have no sign-in session, so the package opens the page and waits for the redirect to arrive as a deep link. The tab opens in the app's task and the redirect closes it. If the user returns to the app without the redirect, the call returns {"type": "dismiss"}.

Close an open page from code with await WebBrowser.dismiss_browser() or WebBrowser.dismiss_auth_session().

Tip: on Android 15 and later, a tab on top puts your app in the background. The system then blocks it from starting activities and freezes it after a few seconds. So dismiss_browser() called while a tab shows may not close it: the call returns and the app resumes when the user leaves the tab. Sign-in redirects are not affected, because the system delivers the deep link.

Warm-up (Android)

await WebBrowser.warm_up_async()                               # start the browser's service early
await WebBrowser.may_init_with_url_async("https://pyxpo.dev")  # preload a page the user will probably open
...
await WebBrowser.cool_down_async()
info = await WebBrowser.get_custom_tabs_supporting_browsers_async()
info["browserPackages"], info["defaultBrowserPackage"]

On iOS and desktop the warm-up functions return {}. get_custom_tabs_supporting_browsers_async raises NotSupportedError on iOS.

Errors

Error When What to do
ValueError The URL is empty, or its scheme is not http or https. A bad dismiss_button_style. Pass a full https:// URL.
NotSupportedError open_auth_session_async on the desktop. get_custom_tabs_supporting_browsers_async on iOS. Use a phone build, or branch on platform().
ModuleNotLinkedError The phone build lacks the module. Add "web-browser" to modules and rebuild.
{"type": "locked"} result A browser or sign-in is already open. Wait for it to close.

Config

scheme in [tool.pyxpo] is the deep-link scheme for sign-in redirects. The package adds an Android queries entry so the app can find browsers and Custom Tabs services. Nothing else is needed.

Web and desktop

open_browser_async calls Python's webbrowser.open, so the system browser opens. dismiss_browser() returns {"type": "dismiss"} without closing anything. maybe_complete_auth_session() returns {"type": "failed", "message": ...}, because only Expo's web target uses it.

Recipe: sign in with an OAuth provider

from urllib.parse import parse_qs, urlencode, urlparse

from pyxpo import Button, Text, View, component, use_async, use_state
import pyxpo_web_browser as WebBrowser

AUTH = "https://auth.example.com/authorize"
REDIRECT = "myapp://callback"


@component
def SignIn():
    taps, set_taps = use_state(0)
    status, set_status = use_state("Signed out")

    async def run():
        if taps == 0:
            return
        url = AUTH + "?" + urlencode({"client_id": "abc", "redirect_uri": REDIRECT,
                                       "response_type": "code", "scope": "openid"})
        res = await WebBrowser.open_auth_session_async(url, REDIRECT, prefer_ephemeral_session=True)
        if res["type"] == "success":
            code = parse_qs(urlparse(res["url"]).query).get("code", [""])[0]
            set_status("Got a code (%d chars). Exchange it on your server." % len(code))
        elif res["type"] == "cancel":
            set_status("Cancelled")
        else:
            set_status("Result: %s" % res["type"])

    use_async(run, [taps])
    return View(Text(status), Button("Sign in", lambda: set_taps(taps + 1)))

Production checklist

  • scheme is set and unique to your app, and matches the redirect URL registered with the provider.
  • You handle all of success, cancel, dismiss and locked.
  • You use the PKCE flow or exchange the code on your server. Never ship a client secret in the app.
  • You check the state value in the returned URL.
  • Only http and https URLs from trusted sources are opened.
  • Sign-in is tested on a real Android device and on iOS.

Testing

Fake the module's native call and the platform to test your result handling:

import asyncio

import pytest

import pyxpo_web_browser as wb


def test_rejects_non_http_urls():
    with pytest.raises(ValueError):
        asyncio.run(wb.open_browser_async("file:///etc/passwd"))


def test_desktop_opens_system_browser(monkeypatch):
    import webbrowser

    seen = []
    monkeypatch.setattr(webbrowser, "open", lambda url: seen.append(url) or True)
    res = asyncio.run(wb.open_browser_async("https://pyxpo.dev"))
    assert res == {"type": "opened"}
    assert seen == ["https://pyxpo.dev"]


def test_auth_needs_a_phone():
    from pyxpo.module_api import NotSupportedError

    with pytest.raises(NotSupportedError):
        asyncio.run(wb.open_auth_session_async("https://a.example/auth", "myapp://cb"))


def test_ios_result(monkeypatch):
    monkeypatch.setattr(wb, "platform", lambda: "ios")
    monkeypatch.setattr(wb, "require_linked", lambda *a, **k: None)

    async def fake_call(*args, **kwargs):
        return {"type": "cancel"}

    monkeypatch.setattr(wb, "call", fake_call)
    assert asyncio.run(wb.open_browser_async("https://pyxpo.dev")) == {"type": "cancel"}

Troubleshooting

Symptom Cause and fix
ValueError about the URL Only http and https are allowed.
Sign-in never returns on Android The redirect does not start with the app scheme, or the provider rejects it. Check both.
"locked" A page is already open.
dismiss_browser() does nothing on Android 15+ The system blocks it while a tab is on top. See the tip under Sign-in.
iOS asks "wants to use ... to sign in" Pass prefer_ephemeral_session=True.
Nothing opens on the desktop The system browser may be missing. Check webbrowser.open.
NotSupportedError You called a phone-only function on the desktop.

FAQ

Is this a WebView? No. It is the system's browser UI, so you get the user's cookies and autofill and cannot read the page.

Can I read the page content? No, by design.

Which browser does Android use? The preferred Custom Tabs browser. Set browser_package to choose.

Can I pass file:// or tel: links? No: http and https only. Use pyxpo.Linking for other schemes.

API reference

Function Returns
open_browser_async(url, **options) A result dict.
dismiss_browser() {"type": "dismiss"} (async).
open_auth_session_async(url, redirect_url=None, **options) A result dict.
dismiss_auth_session() None.
maybe_complete_auth_session() {"type": "failed"}: web only in Expo.
warm_up_async(browser_package=None) Android: dict. Elsewhere {}.
may_init_with_url_async(url, browser_package=None) Android: dict. Elsewhere {}.
cool_down_async(browser_package=None) Android: dict. Elsewhere {}.
get_custom_tabs_supporting_browsers_async() Android: browserPackages, servicePackages, defaultBrowserPackage, preferredBrowserPackage.
WebBrowserResultType, WebBrowserPresentationStyle Enums.

License

MIT

Metadata

Release files for pyxpo-web-browser 0.1.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyxpo-web-browser 0.1.0a2
File Size Uploaded Provenance Actions
pyxpo_web_browser-0.1.0a2.tar.gz 22.0 kB With provenance Details for pyxpo_web_browser-0.1.0a2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyxpo-web-browser 0.1.0a2
File Interpreter ABI Platform Actions
pyxpo_web_browser-0.1.0a2-py3-none-any.whl Python 3 none any Details for pyxpo_web_browser-0.1.0a2-py3-none-any.whl

Total release size: 39.0 kB

Release files / pyxpo_web_browser-0.1.0a2.tar.gz

Download URL pyxpo_web_browser-0.1.0a2.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
aa7a40d9fab92dc4578cfb338d8fbc89f22fab2d23dcad912281c80a090bfba5
BLAKE2b-256 checksum
How to use checksums
8e3dff526f26d6fdff755308accd2332f19c979989922a89b4c5892405727a4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / pyxpo_web_browser-0.1.0a2-py3-none-any.whl

Download URL pyxpo_web_browser-0.1.0a2-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ff4bffe71fff4f24dd1a915c8fc47631f4f8108a00f4a5fc4e01034cc72c2e9
BLAKE2b-256 checksum
How to use checksums
cb57bcb3835b1f0f8426eaf77098b2dc37ca7fca1f6a524c853180b044a7bc7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for pyxpo-web-browser 0.1.0a2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyxpo_web_browser-0.1.0a2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page