-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathload_html.py
More file actions
47 lines (38 loc) · 1.11 KB
/
load_html.py
File metadata and controls
47 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "justbe-webview",
# ]
#
# [tool.uv.sources]
# justbe-webview = { path = "../" }
# ///
import asyncio
from justbe_webview import (
WebView,
Options,
ContentHtml,
Notification,
)
async def main():
print("Creating webview")
config = Options(
title="Load Html Example",
load=ContentHtml(
html="<h1>Initial html</h1>",
# Note: This origin is used with a custom protocol so it doesn't match
# https://example.com. This doesn't need to be set, but can be useful if
# you want to control resources that are scoped to a specific origin like
# local storage or indexeddb.
origin="example.com",
),
devtools=True,
)
async with WebView(config) as webview:
async def handle_start(event: Notification):
await webview.open_devtools()
await webview.load_html("<h1>Updated html!</h1>")
webview.on("started", handle_start)
print("Webview closed")
if __name__ == "__main__":
asyncio.run(main())