native-web-app


Namenative-web-app JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/mhils/native_web_app
SummaryBuild Electron-like apps without Electron
upload_time2020-08-11 21:06:53
maintainer
docs_urlNone
authorMaximilian Hils
requires_python>=3.5
licenseMIT
keywords webbrowser electron browser pwa webapp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
    <img alt="demo app screenshot" width="600" height="215" src="https://uploads.hi.ls/2020-08/example-app.png">
</p>

# native-web-app
![](https://img.shields.io/pypi/wheel/native-web-app.svg)
![](https://img.shields.io/pypi/v/native-web-app.svg)
![](https://img.shields.io/pypi/pyversions/native-web-app.svg)
![](https://img.shields.io/pypi/l/native-web-app.svg)

A drop-in replacement for Python's `webbrowser.open()` 
that opens a native browser window without browser controls. Build Electron-style apps without shipping Electron!

```python
import native_web_app

url = "http://localhost:8000/"

try:
    native_web_app.open(url)
except Exception:
    print(f"No web browser found. Please open a browser and point it to {url}.")
```

## Demo

There is an [example app](https://github.com/mhils/native_web_app/blob/master/example-app.pyw) in the repository.

## API Documentation

This module exposes a single `open` function:

```python
def open(url: str, try_app_mode: bool = True) -> None:
    """
    Open a URL in a modern browser.
    In contrast to webbrowser.open, this method gracefully degrades
    to a no-op on headless servers, where webbrowser.open would otherwise open lynx.

    Args:
        url:
            The URL to open, e.g. http://localhost:1234.
        try_app_mode:
            If True, try to open the URL in "app mode", i.e. without browser controls.
            This allows for Electron-like apps without having to deal with Electron.
            If no suitable browser is found, it gracefully falls back to a regular browser instance.

    Raises:
        RuntimeError, if no suitable browser is found.
        OSError, if the browser executable could not be executed.

        For robustness, implementors should catch any Exception and take that as a signal that opening the URL failed.
    """
```

## Compatibility

OS | Browser | Status (✅ app mode, ☑️ regular browser)
--- | --- | ---
Windows 10 (2004) | Google Chrome 84 | ✅
Windows 10 (2004) | Microsoft Edge 84 | ✅
Windows 10 (2004) | Windows Subsystem for Linux | ☑️
Windows 10 (2004) | Default Browser | ☑️
Ubuntu 20.04 | Google Chrome 84 | ✅
Ubuntu 20.04 | Default Browser | ☑️
macOS Catalina | Google Chrome 84 | ✅
macOS Catalina | Default Browser | ☑️

Firefox implemented app mode ("site-specific browser functionality") in 2020,
but enabled it only for `https://` URLs. This means it [does not work with `http://localhost:1234`
or `file://` URLs](https://bugzilla.mozilla.org/show_bug.cgi?id=1631271).
This makes it unsuitable for inclusion in native_web_app.

## Changelog

This project follows semantic versioning.

#### native_web_app 1.0.2 (2020-08-12)

 - Add support for Python 3.5 and 3.6.

#### native_web_app 1.0.1 (2020-08-12)

 - Enforce browsers to start in background. This fixes
   compatibility with Microsoft Edge on Windows 10.
 - Extend documentation on compatibility.

#### native_web_app 1.0.0 (2020-08-11)

 - Initial Release

## FAQ

#### How do I detect when the browser window is closed?

Monitoring the spawned browser process does not work reliably across platforms.
We recommend you use JavaScript to notify your backend:

```javascript
window.addEventListener('unload', function() {
    navigator.sendBeacon("/shutdown");
}, false);
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mhils/native_web_app",
    "name": "native-web-app",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "webbrowser electron browser pwa webapp",
    "author": "Maximilian Hils",
    "author_email": "pypi@maximilianhils.com",
    "download_url": "",
    "platform": "",
    "description": "<p align=\"center\">\n    <img alt=\"demo app screenshot\" width=\"600\" height=\"215\" src=\"https://uploads.hi.ls/2020-08/example-app.png\">\n</p>\n\n# native-web-app\n![](https://img.shields.io/pypi/wheel/native-web-app.svg)\n![](https://img.shields.io/pypi/v/native-web-app.svg)\n![](https://img.shields.io/pypi/pyversions/native-web-app.svg)\n![](https://img.shields.io/pypi/l/native-web-app.svg)\n\nA drop-in replacement for Python's `webbrowser.open()` \nthat opens a native browser window without browser controls. Build Electron-style apps without shipping Electron!\n\n```python\nimport native_web_app\n\nurl = \"http://localhost:8000/\"\n\ntry:\n    native_web_app.open(url)\nexcept Exception:\n    print(f\"No web browser found. Please open a browser and point it to {url}.\")\n```\n\n## Demo\n\nThere is an [example app](https://github.com/mhils/native_web_app/blob/master/example-app.pyw) in the repository.\n\n## API Documentation\n\nThis module exposes a single `open` function:\n\n```python\ndef open(url: str, try_app_mode: bool = True) -> None:\n    \"\"\"\n    Open a URL in a modern browser.\n    In contrast to webbrowser.open, this method gracefully degrades\n    to a no-op on headless servers, where webbrowser.open would otherwise open lynx.\n\n    Args:\n        url:\n            The URL to open, e.g. http://localhost:1234.\n        try_app_mode:\n            If True, try to open the URL in \"app mode\", i.e. without browser controls.\n            This allows for Electron-like apps without having to deal with Electron.\n            If no suitable browser is found, it gracefully falls back to a regular browser instance.\n\n    Raises:\n        RuntimeError, if no suitable browser is found.\n        OSError, if the browser executable could not be executed.\n\n        For robustness, implementors should catch any Exception and take that as a signal that opening the URL failed.\n    \"\"\"\n```\n\n## Compatibility\n\nOS | Browser | Status (\u2705 app mode, \u2611\ufe0f regular browser)\n--- | --- | ---\nWindows 10 (2004) | Google Chrome 84 | \u2705\nWindows 10 (2004) | Microsoft Edge 84 | \u2705\nWindows 10 (2004) | Windows Subsystem for Linux | \u2611\ufe0f\nWindows 10 (2004) | Default Browser | \u2611\ufe0f\nUbuntu 20.04 | Google Chrome 84 | \u2705\nUbuntu 20.04 | Default Browser | \u2611\ufe0f\nmacOS Catalina | Google Chrome 84 | \u2705\nmacOS Catalina | Default Browser | \u2611\ufe0f\n\nFirefox implemented app mode (\"site-specific browser functionality\") in 2020,\nbut enabled it only for `https://` URLs. This means it [does not work with `http://localhost:1234`\nor `file://` URLs](https://bugzilla.mozilla.org/show_bug.cgi?id=1631271).\nThis makes it unsuitable for inclusion in native_web_app.\n\n## Changelog\n\nThis project follows semantic versioning.\n\n#### native_web_app 1.0.2 (2020-08-12)\n\n - Add support for Python 3.5 and 3.6.\n\n#### native_web_app 1.0.1 (2020-08-12)\n\n - Enforce browsers to start in background. This fixes\n   compatibility with Microsoft Edge on Windows 10.\n - Extend documentation on compatibility.\n\n#### native_web_app 1.0.0 (2020-08-11)\n\n - Initial Release\n\n## FAQ\n\n#### How do I detect when the browser window is closed?\n\nMonitoring the spawned browser process does not work reliably across platforms.\nWe recommend you use JavaScript to notify your backend:\n\n```javascript\nwindow.addEventListener('unload', function() {\n    navigator.sendBeacon(\"/shutdown\");\n}, false);\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Build Electron-like apps without Electron",
    "version": "1.0.2",
    "split_keywords": [
        "webbrowser",
        "electron",
        "browser",
        "pwa",
        "webapp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "911aef7e8ae2b7e3f2a3add94cd19cb3",
                "sha256": "2259aae94852dabbaaf99ba884983518d44dfb9b669fefa16fa89dc18a61f1a8"
            },
            "downloads": -1,
            "filename": "native_web_app-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "911aef7e8ae2b7e3f2a3add94cd19cb3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 5215,
            "upload_time": "2020-08-11T21:06:53",
            "upload_time_iso_8601": "2020-08-11T21:06:53.759705Z",
            "url": "https://files.pythonhosted.org/packages/a2/fb/d213b13689929d857605df15f1eee712e1f80f1d5639ceeba1a2f87a971b/native_web_app-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-08-11 21:06:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "mhils",
    "error": "Could not fetch GitHub repository",
    "lcname": "native-web-app"
}
        
Elapsed time: 0.26297s