无需Electron即可构建类似Electron的应用
项目描述
native-web-app
Python的webbrowser.open()
的替代品,可以打开不带浏览器控制的本地浏览器窗口。无需发布Electron即可构建Electron风格的应用!
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}.")
演示
在仓库中有一个 示例应用。
API文档
此模块公开了一个open
函数
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.
"""
兼容性
OS | 浏览器 | 状态(✅应用模式,☑️常规浏览器) |
---|---|---|
Windows 10 (2004) | Google Chrome 84 | ✅ |
Windows 10 (2004) | Microsoft Edge 84 | ✅ |
Windows 10 (2004) | Windows Subsystem for Linux | ☑️ |
Windows 10 (2004) | 默认浏览器 | ☑️ |
Ubuntu 20.04 | Google Chrome 84 | ✅ |
Ubuntu 20.04 | 默认浏览器 | ☑️ |
macOS Catalina | Google Chrome 84 | ✅ |
macOS Catalina | 默认浏览器 | ☑️ |
Firefox在2020年实现了应用模式(“特定站点浏览器功能”),但仅对https://
URL启用。这意味着它 无法与http://localhost:1234
或file://
URL一起使用。这使得它不适合包含在native_web_app中。
变更日志
此项目遵循语义版本控制。
native_web_app 1.0.2 (2020-08-12)
- 添加对Python 3.5和3.6的支持。
native_web_app 1.0.1 (2020-08-12)
- 强制浏览器在后台启动。这修复了与Windows 10上Microsoft Edge的兼容性。
- 扩展兼容性文档。
native_web_app 1.0.0 (2020-08-11)
- 初始发布
常见问题解答
如何检测浏览器窗口何时关闭?
在各个平台上监控生成的浏览器进程并不稳定。我们建议您使用JavaScript来通知后端。
window.addEventListener('unload', function() {
navigator.sendBeacon("/shutdown");
}, false);
项目详情
关闭
native_web_app-1.0.2-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2259aae94852dabbaaf99ba884983518d44dfb9b669fefa16fa89dc18a61f1a8 |
|
MD5 | 911aef7e8ae2b7e3f2a3add94cd19cb3 |
|
BLAKE2b-256 | a2fbd213b13689929d857605df15f1eee712e1f80f1d5639ceeba1a2f87a971b |