File: browser.py

package info (click to toggle)
python-trame-server 3.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 480 kB
  • sloc: python: 4,075; javascript: 5; sh: 4; makefile: 3
file content (15 lines) | stat: -rw-r--r-- 455 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def open_browser(server):
    args = server.cli.parse_known_args()[0]
    local_url = f"http://{args.host}:{server.port}/"
    try:
        import asyncio
        import webbrowser

        loop = asyncio.get_event_loop()
        loop.call_later(0.1, lambda: webbrowser.open(local_url))
        print(
            "And to prevent your browser from opening, "
            "add '--server' to your command line."
        )
    except Exception:
        pass