flet-webview 0.1.0.dev1__py3-none-any.whl → 0.2.0.dev49__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flet-webview might be problematic. Click here for more details.
- flet_webview/__init__.py +7 -7
- flet_webview/types.py +71 -0
- flet_webview/webview.py +432 -413
- flet_webview-0.2.0.dev49.dist-info/METADATA +67 -0
- flet_webview-0.2.0.dev49.dist-info/RECORD +23 -0
- {flet_webview-0.1.0.dev1.dist-info → flet_webview-0.2.0.dev49.dist-info}/WHEEL +1 -1
- flet_webview-0.2.0.dev49.dist-info/licenses/LICENSE +201 -0
- flutter/flet_webview/lib/flet_webview.dart +1 -1
- flutter/flet_webview/lib/src/extension.dart +16 -0
- flutter/flet_webview/lib/src/utils/webview.dart +3 -5
- flutter/flet_webview/lib/src/webview.dart +7 -19
- flutter/flet_webview/lib/src/webview_mobile_and_mac.dart +129 -143
- flutter/flet_webview/lib/src/webview_web.dart +2 -3
- flutter/flet_webview/lib/src/webview_web_vain.dart +2 -8
- flutter/flet_webview/lib/src/webview_windows_and_linux.dart +2 -9
- flutter/flet_webview/lib/src/webview_windows_and_linux_vain.dart +1 -3
- flutter/flet_webview/pubspec.lock +175 -126
- flutter/flet_webview/pubspec.yaml +10 -5
- flet_webview-0.1.0.dev1.dist-info/METADATA +0 -42
- flet_webview-0.1.0.dev1.dist-info/RECORD +0 -21
- flutter/flet_webview/lib/src/create_control.dart +0 -20
- {flet_webview-0.1.0.dev1.dist-info → flet_webview-0.2.0.dev49.dist-info}/top_level.txt +0 -0
flet_webview/webview.py
CHANGED
|
@@ -1,498 +1,517 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
from flet.core.event_handler import EventHandler
|
|
12
|
-
from flet.core.exceptions import FletUnsupportedPlatformException
|
|
13
|
-
from flet.core.ref import Ref
|
|
14
|
-
from flet.core.tooltip import TooltipValue
|
|
15
|
-
from flet.core.types import (
|
|
16
|
-
ColorEnums,
|
|
17
|
-
ColorValue,
|
|
18
|
-
OffsetValue,
|
|
19
|
-
OptionalControlEventCallable,
|
|
20
|
-
OptionalEventCallable,
|
|
21
|
-
PagePlatform,
|
|
22
|
-
ResponsiveNumber,
|
|
23
|
-
RotateValue,
|
|
24
|
-
ScaleValue,
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
|
|
4
|
+
import flet as ft
|
|
5
|
+
|
|
6
|
+
from .types import (
|
|
7
|
+
RequestMethod,
|
|
8
|
+
WebViewConsoleMessageEvent,
|
|
9
|
+
WebViewJavaScriptEvent,
|
|
10
|
+
WebViewScrollEvent,
|
|
25
11
|
)
|
|
26
12
|
|
|
13
|
+
__all__ = ["WebView"]
|
|
27
14
|
|
|
28
|
-
class WebviewRequestMethod(Enum):
|
|
29
|
-
GET = "get"
|
|
30
|
-
POST = "post"
|
|
31
15
|
|
|
16
|
+
@ft.control("WebView")
|
|
17
|
+
class WebView(ft.ConstrainedControl):
|
|
18
|
+
"""
|
|
19
|
+
Easily load webpages while allowing user interaction.
|
|
32
20
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
DEBUG = "debug"
|
|
37
|
-
INFO = "info"
|
|
38
|
-
LOG = "log"
|
|
21
|
+
Note:
|
|
22
|
+
Works only on the following platforms: iOS, Android, macOS and Web.
|
|
23
|
+
"""
|
|
39
24
|
|
|
25
|
+
url: str
|
|
26
|
+
"""The URL of the web page to load."""
|
|
40
27
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
enable_javascript: Optional[bool] = None
|
|
29
|
+
"""
|
|
30
|
+
Enable or disable the JavaScript execution on the page.
|
|
31
|
+
|
|
32
|
+
Note that disabling the JavaScript execution on the page may result to unexpected web page behaviour.
|
|
33
|
+
"""
|
|
47
34
|
|
|
35
|
+
prevent_links: Optional[List[str]] = None
|
|
36
|
+
"""List of url-prefixes that should not be followed/loaded/downloaded."""
|
|
48
37
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
super().__init__(e.target, e.name, e.data, e.control, e.page)
|
|
52
|
-
d = json.loads(e.data)
|
|
53
|
-
self.message: str = d.get("message")
|
|
54
|
-
self.severity_level: WebviewLogLevelSeverity = WebviewLogLevelSeverity(
|
|
55
|
-
d.get("level")
|
|
56
|
-
)
|
|
38
|
+
bgcolor: Optional[ft.ColorValue] = None
|
|
39
|
+
"""Defines the background color of the WebView."""
|
|
57
40
|
|
|
41
|
+
on_page_started: ft.OptionalControlEventHandler["WebView"] = None
|
|
42
|
+
"""
|
|
43
|
+
Fires soon as the first loading process of the webview page is started.
|
|
44
|
+
|
|
45
|
+
Event handler argument's `data` property is of type `str` and contains the URL.
|
|
46
|
+
|
|
47
|
+
Note:
|
|
48
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
49
|
+
"""
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
on_page_ended: ft.OptionalControlEventHandler["WebView"] = None
|
|
52
|
+
"""
|
|
53
|
+
Fires when all the webview page loading processes are ended.
|
|
54
|
+
|
|
55
|
+
Event handler argument's `data` property is of type `str` and contains the URL.
|
|
56
|
+
|
|
57
|
+
Note:
|
|
58
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
59
|
+
"""
|
|
65
60
|
|
|
61
|
+
on_web_resource_error: ft.OptionalControlEventHandler["WebView"] = None
|
|
62
|
+
"""
|
|
63
|
+
Fires when there is error with loading a webview page resource.
|
|
64
|
+
|
|
65
|
+
Event handler argument's `data` property is of type `str` and contains the error message.
|
|
66
|
+
|
|
67
|
+
Note:
|
|
68
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
69
|
+
"""
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
on_progress: ft.OptionalControlEventHandler["WebView"] = None
|
|
72
|
+
"""
|
|
73
|
+
Fires when the progress of the webview page loading is changed.
|
|
74
|
+
|
|
75
|
+
Event handler argument's `data` property is of type `int` and contains the progress value.
|
|
76
|
+
|
|
77
|
+
Note:
|
|
78
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
68
79
|
"""
|
|
69
|
-
Easily load webpages while allowing user interaction.
|
|
70
80
|
|
|
71
|
-
|
|
81
|
+
on_url_change: ft.OptionalControlEventHandler["WebView"] = None
|
|
82
|
+
"""
|
|
83
|
+
Fires when the URL of the webview page is changed.
|
|
84
|
+
|
|
85
|
+
Event handler argument's `data` property is of type `str` and contains the new URL.
|
|
86
|
+
|
|
87
|
+
Note:
|
|
88
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
89
|
+
"""
|
|
72
90
|
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
on_scroll: ft.OptionalEventHandler[WebViewScrollEvent["WebView"]] = None
|
|
92
|
+
"""
|
|
93
|
+
Fires when the web page's scroll position changes.
|
|
94
|
+
|
|
95
|
+
Event handler argument is of type `WebviewScrollEvent`.
|
|
96
|
+
|
|
97
|
+
Note:
|
|
98
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
99
|
+
"""
|
|
75
100
|
|
|
76
|
-
|
|
77
|
-
|
|
101
|
+
on_console_message: ft.OptionalEventHandler[
|
|
102
|
+
WebViewConsoleMessageEvent["WebView"]
|
|
103
|
+
] = None
|
|
104
|
+
"""
|
|
105
|
+
Fires when a log message is written to the JavaScript console.
|
|
106
|
+
|
|
107
|
+
Event handler argument is of type `WebviewConsoleMessageEvent`.
|
|
108
|
+
|
|
109
|
+
Note:
|
|
110
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
111
|
+
"""
|
|
78
112
|
|
|
79
|
-
|
|
113
|
+
on_javascript_alert_dialog: ft.OptionalEventHandler[
|
|
114
|
+
WebViewJavaScriptEvent["WebView"]
|
|
115
|
+
] = None
|
|
116
|
+
"""
|
|
117
|
+
Fires when the web page attempts to display a JavaScript alert() dialog.
|
|
118
|
+
|
|
119
|
+
Event handler argument is of type `WebviewJavaScriptEvent`.
|
|
120
|
+
|
|
121
|
+
Note:
|
|
122
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
123
|
+
"""
|
|
80
124
|
|
|
81
|
-
def
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
125
|
+
def _check_mobile_or_mac_platform(self):
|
|
126
|
+
"""Checks/Validates support for the current platform (iOS, Android, or macOS)."""
|
|
127
|
+
assert self.page is not None, "WebView must be added to page first."
|
|
128
|
+
if self.page.web or self.page.platform not in [
|
|
129
|
+
ft.PagePlatform.ANDROID,
|
|
130
|
+
ft.PagePlatform.IOS,
|
|
131
|
+
ft.PagePlatform.MACOS,
|
|
132
|
+
]:
|
|
133
|
+
raise ft.FletUnsupportedPlatformException(
|
|
134
|
+
"This method is supported on Android, iOS and macOS platforms only."
|
|
135
|
+
)
|
|
90
136
|
|
|
91
|
-
|
|
92
|
-
|
|
137
|
+
def reload(self):
|
|
138
|
+
"""
|
|
139
|
+
Reloads the current URL.
|
|
93
140
|
|
|
94
|
-
|
|
141
|
+
Note:
|
|
142
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
143
|
+
"""
|
|
144
|
+
self._check_mobile_or_mac_platform()
|
|
145
|
+
asyncio.create_task(self.reload_async())
|
|
95
146
|
|
|
96
|
-
|
|
147
|
+
async def reload_async(self):
|
|
148
|
+
"""
|
|
149
|
+
Reloads the current URL.
|
|
97
150
|
|
|
98
|
-
|
|
151
|
+
Note:
|
|
152
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
153
|
+
"""
|
|
154
|
+
self._check_mobile_or_mac_platform()
|
|
155
|
+
await self._invoke_method_async("reload")
|
|
99
156
|
|
|
100
|
-
|
|
157
|
+
async def can_go_back_async(self) -> bool:
|
|
158
|
+
"""
|
|
159
|
+
Whether there's a back history item.
|
|
101
160
|
|
|
102
|
-
|
|
161
|
+
Returns:
|
|
162
|
+
`True` if there is a back history item, `False` otherwise.
|
|
103
163
|
|
|
104
|
-
|
|
164
|
+
Note:
|
|
165
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
166
|
+
"""
|
|
167
|
+
self._check_mobile_or_mac_platform()
|
|
168
|
+
return await self._invoke_method_async("can_go_back")
|
|
105
169
|
|
|
106
|
-
|
|
170
|
+
async def can_go_forward(self) -> bool:
|
|
171
|
+
"""
|
|
172
|
+
Whether there's a forward history item.
|
|
107
173
|
|
|
108
|
-
|
|
174
|
+
Returns:
|
|
175
|
+
`True` if there is a forward history item, `False` otherwise.
|
|
109
176
|
|
|
110
|
-
|
|
177
|
+
Note:
|
|
178
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
179
|
+
"""
|
|
180
|
+
self._check_mobile_or_mac_platform()
|
|
181
|
+
return await self._invoke_method_async("can_go_forward")
|
|
111
182
|
|
|
112
|
-
|
|
183
|
+
def go_back(self):
|
|
184
|
+
"""
|
|
185
|
+
Go back in the history of the webview, if `can_go_back()` is `True`.
|
|
113
186
|
|
|
114
|
-
|
|
187
|
+
Note:
|
|
188
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
189
|
+
"""
|
|
190
|
+
self._check_mobile_or_mac_platform()
|
|
191
|
+
asyncio.create_task(self.go_back_async())
|
|
115
192
|
|
|
116
|
-
|
|
193
|
+
async def go_back_async(self):
|
|
194
|
+
"""
|
|
195
|
+
Go back in the history of the webview, if `can_go_back()` is `True`.
|
|
117
196
|
|
|
118
|
-
|
|
197
|
+
Note:
|
|
198
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
199
|
+
"""
|
|
200
|
+
self._check_mobile_or_mac_platform()
|
|
201
|
+
await self._invoke_method_async("go_back")
|
|
119
202
|
|
|
120
|
-
|
|
203
|
+
def go_forward(self):
|
|
204
|
+
"""
|
|
205
|
+
Go forward in the history of the webview, if `can_go_forward()` is `True`.
|
|
121
206
|
|
|
122
|
-
|
|
207
|
+
Note:
|
|
208
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
209
|
+
"""
|
|
210
|
+
self._check_mobile_or_mac_platform()
|
|
211
|
+
asyncio.create_task(self.go_forward_async())
|
|
123
212
|
|
|
124
|
-
|
|
213
|
+
async def go_forward_async(self):
|
|
214
|
+
"""
|
|
215
|
+
Go forward in the history of the webview, if `can_go_forward()` is `True`.
|
|
125
216
|
|
|
126
|
-
|
|
127
|
-
|
|
217
|
+
Note:
|
|
218
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
219
|
+
"""
|
|
220
|
+
self._check_mobile_or_mac_platform()
|
|
221
|
+
await self._invoke_method_async("go_forward")
|
|
128
222
|
|
|
129
|
-
def
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
javascript_enabled: Optional[bool] = None,
|
|
133
|
-
enable_javascript: Optional[bool] = None,
|
|
134
|
-
prevent_link: Optional[str] = None,
|
|
135
|
-
bgcolor: Optional[ColorValue] = None,
|
|
136
|
-
on_page_started: OptionalControlEventCallable = None,
|
|
137
|
-
on_page_ended: OptionalControlEventCallable = None,
|
|
138
|
-
on_web_resource_error: OptionalControlEventCallable = None,
|
|
139
|
-
on_progress: OptionalControlEventCallable = None,
|
|
140
|
-
on_url_change: OptionalControlEventCallable = None,
|
|
141
|
-
on_scroll: OptionalEventCallable[WebviewScrollEvent] = None,
|
|
142
|
-
on_console_message: OptionalEventCallable[WebviewConsoleMessageEvent] = None,
|
|
143
|
-
on_javascript_alert_dialog: OptionalEventCallable[
|
|
144
|
-
WebviewJavaScriptEvent
|
|
145
|
-
] = None,
|
|
146
|
-
#
|
|
147
|
-
# ConstrainedControl
|
|
148
|
-
#
|
|
149
|
-
ref: Optional[Ref] = None,
|
|
150
|
-
key: Optional[str] = None,
|
|
151
|
-
width: OptionalNumber = None,
|
|
152
|
-
height: OptionalNumber = None,
|
|
153
|
-
left: OptionalNumber = None,
|
|
154
|
-
top: OptionalNumber = None,
|
|
155
|
-
right: OptionalNumber = None,
|
|
156
|
-
bottom: OptionalNumber = None,
|
|
157
|
-
expand: Union[None, bool, int] = None,
|
|
158
|
-
expand_loose: Optional[bool] = None,
|
|
159
|
-
col: Optional[ResponsiveNumber] = None,
|
|
160
|
-
opacity: OptionalNumber = None,
|
|
161
|
-
rotate: RotateValue = None,
|
|
162
|
-
scale: ScaleValue = None,
|
|
163
|
-
offset: OffsetValue = None,
|
|
164
|
-
aspect_ratio: OptionalNumber = None,
|
|
165
|
-
animate_opacity: Optional[AnimationValue] = None,
|
|
166
|
-
animate_size: Optional[AnimationValue] = None,
|
|
167
|
-
animate_position: Optional[AnimationValue] = None,
|
|
168
|
-
animate_rotation: Optional[AnimationValue] = None,
|
|
169
|
-
animate_scale: Optional[AnimationValue] = None,
|
|
170
|
-
animate_offset: Optional[AnimationValue] = None,
|
|
171
|
-
on_animation_end: OptionalControlEventCallable = None,
|
|
172
|
-
tooltip: TooltipValue = None,
|
|
173
|
-
badge: Optional[BadgeValue] = None,
|
|
174
|
-
visible: Optional[bool] = None,
|
|
175
|
-
disabled: Optional[bool] = None,
|
|
176
|
-
data: Any = None,
|
|
177
|
-
):
|
|
178
|
-
ConstrainedControl.__init__(
|
|
179
|
-
self,
|
|
180
|
-
ref=ref,
|
|
181
|
-
key=key,
|
|
182
|
-
width=width,
|
|
183
|
-
height=height,
|
|
184
|
-
left=left,
|
|
185
|
-
top=top,
|
|
186
|
-
right=right,
|
|
187
|
-
bottom=bottom,
|
|
188
|
-
expand=expand,
|
|
189
|
-
expand_loose=expand_loose,
|
|
190
|
-
col=col,
|
|
191
|
-
opacity=opacity,
|
|
192
|
-
rotate=rotate,
|
|
193
|
-
scale=scale,
|
|
194
|
-
offset=offset,
|
|
195
|
-
aspect_ratio=aspect_ratio,
|
|
196
|
-
animate_opacity=animate_opacity,
|
|
197
|
-
animate_size=animate_size,
|
|
198
|
-
animate_position=animate_position,
|
|
199
|
-
animate_rotation=animate_rotation,
|
|
200
|
-
animate_scale=animate_scale,
|
|
201
|
-
animate_offset=animate_offset,
|
|
202
|
-
on_animation_end=on_animation_end,
|
|
203
|
-
tooltip=tooltip,
|
|
204
|
-
badge=badge,
|
|
205
|
-
visible=visible,
|
|
206
|
-
disabled=disabled,
|
|
207
|
-
data=data,
|
|
208
|
-
)
|
|
209
|
-
self.__on_scroll = EventHandler(lambda e: WebviewScrollEvent(e))
|
|
210
|
-
self._add_event_handler("scroll", self.__on_scroll.get_handler())
|
|
211
|
-
self.__on_console_message = EventHandler(
|
|
212
|
-
lambda e: WebviewConsoleMessageEvent(e)
|
|
213
|
-
)
|
|
214
|
-
self._add_event_handler(
|
|
215
|
-
"console_message", self.__on_console_message.get_handler()
|
|
216
|
-
)
|
|
217
|
-
self.__on_javascript_alert_dialog = EventHandler(
|
|
218
|
-
lambda e: WebviewJavaScriptEvent(e)
|
|
219
|
-
)
|
|
220
|
-
self._add_event_handler(
|
|
221
|
-
"javascript_alert_dialog", self.__on_javascript_alert_dialog.get_handler()
|
|
222
|
-
)
|
|
223
|
+
def enable_zoom(self):
|
|
224
|
+
"""
|
|
225
|
+
Enable zooming using the on-screen zoom controls and gestures.
|
|
223
226
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
self.
|
|
228
|
-
self.
|
|
229
|
-
self.on_page_started = on_page_started
|
|
230
|
-
self.on_page_ended = on_page_ended
|
|
231
|
-
self.on_web_resource_error = on_web_resource_error
|
|
232
|
-
self.on_progress = on_progress
|
|
233
|
-
self.on_url_change = on_url_change
|
|
234
|
-
self.on_scroll = on_scroll
|
|
235
|
-
self.on_console_message = on_console_message
|
|
236
|
-
self.on_javascript_alert_dialog = on_javascript_alert_dialog
|
|
237
|
-
|
|
238
|
-
def _get_control_name(self):
|
|
239
|
-
return "webview"
|
|
227
|
+
Note:
|
|
228
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
229
|
+
"""
|
|
230
|
+
self._check_mobile_or_mac_platform()
|
|
231
|
+
asyncio.create_task(self.enable_zoom_async())
|
|
240
232
|
|
|
241
|
-
def
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
PagePlatform.ANDROID,
|
|
245
|
-
PagePlatform.IOS,
|
|
246
|
-
PagePlatform.MACOS,
|
|
247
|
-
]:
|
|
248
|
-
raise FletUnsupportedPlatformException(
|
|
249
|
-
"This method is supported on Android, iOS and macOS platforms only."
|
|
250
|
-
)
|
|
233
|
+
async def enable_zoom_async(self):
|
|
234
|
+
"""
|
|
235
|
+
Enable zooming using the on-screen zoom controls and gestures.
|
|
251
236
|
|
|
252
|
-
|
|
237
|
+
Note:
|
|
238
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
239
|
+
"""
|
|
253
240
|
self._check_mobile_or_mac_platform()
|
|
254
|
-
self.
|
|
241
|
+
await self._invoke_method_async("enable_zoom")
|
|
242
|
+
|
|
243
|
+
def disable_zoom(self):
|
|
244
|
+
"""
|
|
245
|
+
Disable zooming using the on-screen zoom controls and gestures.
|
|
255
246
|
|
|
256
|
-
|
|
247
|
+
Note:
|
|
248
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
249
|
+
"""
|
|
257
250
|
self._check_mobile_or_mac_platform()
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
)
|
|
264
|
-
== "true"
|
|
265
|
-
)
|
|
251
|
+
asyncio.create_task(self.disable_zoom_async())
|
|
252
|
+
|
|
253
|
+
async def disable_zoom_async(self):
|
|
254
|
+
"""
|
|
255
|
+
Disable zooming using the on-screen zoom controls and gestures.
|
|
266
256
|
|
|
267
|
-
|
|
257
|
+
Note:
|
|
258
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
259
|
+
"""
|
|
268
260
|
self._check_mobile_or_mac_platform()
|
|
269
|
-
|
|
270
|
-
self.invoke_method(
|
|
271
|
-
"can_go_forward",
|
|
272
|
-
wait_for_result=True,
|
|
273
|
-
wait_timeout=wait_timeout,
|
|
274
|
-
)
|
|
275
|
-
== "true"
|
|
276
|
-
)
|
|
261
|
+
await self._invoke_method_async("disable_zoom")
|
|
277
262
|
|
|
278
|
-
def
|
|
263
|
+
def clear_cache(self):
|
|
264
|
+
"""
|
|
265
|
+
Clears all caches used by the WebView.
|
|
266
|
+
|
|
267
|
+
The following caches are cleared:
|
|
268
|
+
- Browser HTTP Cache
|
|
269
|
+
- Cache API caches. Service workers tend to use this cache.
|
|
270
|
+
- Application cache
|
|
271
|
+
|
|
272
|
+
Note:
|
|
273
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
274
|
+
"""
|
|
279
275
|
self._check_mobile_or_mac_platform()
|
|
280
|
-
self.
|
|
276
|
+
asyncio.create_task(self.clear_cache_async())
|
|
281
277
|
|
|
282
|
-
def
|
|
278
|
+
async def clear_cache_async(self):
|
|
279
|
+
"""
|
|
280
|
+
Clears all caches used by the WebView.
|
|
281
|
+
|
|
282
|
+
The following caches are cleared:
|
|
283
|
+
- Browser HTTP Cache
|
|
284
|
+
- Cache API caches. Service workers tend to use this cache.
|
|
285
|
+
- Application cache
|
|
286
|
+
|
|
287
|
+
Note:
|
|
288
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
289
|
+
"""
|
|
283
290
|
self._check_mobile_or_mac_platform()
|
|
284
|
-
self.
|
|
291
|
+
await self._invoke_method_async("clear_cache")
|
|
285
292
|
|
|
286
|
-
def
|
|
293
|
+
def clear_local_storage(self):
|
|
294
|
+
"""
|
|
295
|
+
Clears the local storage used by the WebView.
|
|
296
|
+
|
|
297
|
+
Note:
|
|
298
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
299
|
+
"""
|
|
287
300
|
self._check_mobile_or_mac_platform()
|
|
288
|
-
self.
|
|
301
|
+
asyncio.create_task(self.clear_local_storage_async())
|
|
289
302
|
|
|
290
|
-
def
|
|
303
|
+
async def clear_local_storage_async(self):
|
|
304
|
+
"""
|
|
305
|
+
Clears the local storage used by the WebView.
|
|
306
|
+
|
|
307
|
+
Note:
|
|
308
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
309
|
+
"""
|
|
291
310
|
self._check_mobile_or_mac_platform()
|
|
292
|
-
self.
|
|
311
|
+
await self._invoke_method_async("clear_local_storage")
|
|
293
312
|
|
|
294
|
-
def
|
|
313
|
+
async def get_current_url_async(self) -> Optional[str]:
|
|
314
|
+
"""
|
|
315
|
+
Returns the current URL that the WebView is displaying or `None` if no URL was ever loaded.
|
|
316
|
+
|
|
317
|
+
Returns:
|
|
318
|
+
The current URL that the WebView is displaying or `None` if no URL was ever loaded.
|
|
319
|
+
|
|
320
|
+
Note:
|
|
321
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
322
|
+
"""
|
|
295
323
|
self._check_mobile_or_mac_platform()
|
|
296
|
-
self.
|
|
324
|
+
return await self._invoke_method_async("get_current_url")
|
|
297
325
|
|
|
298
|
-
def
|
|
326
|
+
async def get_title_async(self) -> Optional[str]:
|
|
327
|
+
"""
|
|
328
|
+
Returns the title of the currently loaded page.
|
|
329
|
+
|
|
330
|
+
Returns:
|
|
331
|
+
The title of the currently loaded page.
|
|
332
|
+
|
|
333
|
+
Note:
|
|
334
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
335
|
+
"""
|
|
299
336
|
self._check_mobile_or_mac_platform()
|
|
300
|
-
self.
|
|
337
|
+
return await self._invoke_method_async("get_title")
|
|
338
|
+
|
|
339
|
+
async def get_user_agent_async(self) -> Optional[str]:
|
|
340
|
+
"""
|
|
341
|
+
Returns the value used for the HTTP `User-Agent:` request header.
|
|
301
342
|
|
|
302
|
-
|
|
343
|
+
Returns:
|
|
344
|
+
The value used for the HTTP `User-Agent:` request header.
|
|
345
|
+
|
|
346
|
+
Note:
|
|
347
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
348
|
+
"""
|
|
303
349
|
self._check_mobile_or_mac_platform()
|
|
304
|
-
return self.
|
|
305
|
-
"get_current_url", wait_for_result=True, wait_timeout=wait_timeout
|
|
306
|
-
)
|
|
350
|
+
return await self._invoke_method_async("get_user_agent")
|
|
307
351
|
|
|
308
|
-
def
|
|
352
|
+
def load_file(self, path: str):
|
|
353
|
+
"""
|
|
354
|
+
Loads the provided local file.
|
|
355
|
+
|
|
356
|
+
Args:
|
|
357
|
+
path: The absolute path to the file.
|
|
358
|
+
|
|
359
|
+
Note:
|
|
360
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
361
|
+
"""
|
|
309
362
|
self._check_mobile_or_mac_platform()
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
363
|
+
asyncio.create_task(self.load_file_async(path))
|
|
364
|
+
|
|
365
|
+
async def load_file_async(self, path: str):
|
|
366
|
+
"""
|
|
367
|
+
Loads the provided local file.
|
|
313
368
|
|
|
314
|
-
|
|
369
|
+
Args:
|
|
370
|
+
path: The absolute path to the file.
|
|
371
|
+
|
|
372
|
+
Note:
|
|
373
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
374
|
+
"""
|
|
315
375
|
self._check_mobile_or_mac_platform()
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
376
|
+
await self._invoke_method_async("load_file", arguments={"path": path})
|
|
377
|
+
|
|
378
|
+
def load_request(self, url: str, method: RequestMethod = RequestMethod.GET):
|
|
379
|
+
"""
|
|
380
|
+
Makes an HTTP request and loads the response in the webview.
|
|
319
381
|
|
|
320
|
-
|
|
382
|
+
Args:
|
|
383
|
+
url: The URL to load.
|
|
384
|
+
method: The HTTP method to use.
|
|
385
|
+
"""
|
|
321
386
|
self._check_mobile_or_mac_platform()
|
|
322
|
-
self.
|
|
387
|
+
asyncio.create_task(self.load_request_async(url, method))
|
|
323
388
|
|
|
324
|
-
def
|
|
325
|
-
self, url: str, method:
|
|
389
|
+
async def load_request_async(
|
|
390
|
+
self, url: str, method: RequestMethod = RequestMethod.GET
|
|
326
391
|
):
|
|
392
|
+
"""
|
|
393
|
+
Makes an HTTP request and loads the response in the webview.
|
|
394
|
+
|
|
395
|
+
Args:
|
|
396
|
+
url: The URL to load.
|
|
397
|
+
method: The HTTP method to use.
|
|
398
|
+
|
|
399
|
+
Note:
|
|
400
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
401
|
+
"""
|
|
327
402
|
self._check_mobile_or_mac_platform()
|
|
328
|
-
self.
|
|
329
|
-
"load_request",
|
|
330
|
-
arguments={"url": url, "method": method.value},
|
|
403
|
+
await self._invoke_method_async(
|
|
404
|
+
"load_request", arguments={"url": url, "method": method}
|
|
331
405
|
)
|
|
332
406
|
|
|
333
407
|
def run_javascript(self, value: str):
|
|
408
|
+
"""
|
|
409
|
+
Runs the given JavaScript in the context of the current page.
|
|
410
|
+
|
|
411
|
+
Args:
|
|
412
|
+
value: The JavaScript code to run.
|
|
413
|
+
|
|
414
|
+
Note:
|
|
415
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
416
|
+
"""
|
|
417
|
+
self._check_mobile_or_mac_platform()
|
|
418
|
+
asyncio.create_task(self.run_javascript_async(value))
|
|
419
|
+
|
|
420
|
+
async def run_javascript_async(self, value: str):
|
|
421
|
+
"""
|
|
422
|
+
Runs the given JavaScript in the context of the current page.
|
|
423
|
+
|
|
424
|
+
Args:
|
|
425
|
+
value: The JavaScript code to run.
|
|
426
|
+
|
|
427
|
+
Note:
|
|
428
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
429
|
+
"""
|
|
334
430
|
self._check_mobile_or_mac_platform()
|
|
335
|
-
self.
|
|
431
|
+
await self._invoke_method_async("run_javascript", arguments={"value": value})
|
|
336
432
|
|
|
337
433
|
def load_html(self, value: str, base_url: Optional[str] = None):
|
|
434
|
+
"""
|
|
435
|
+
Loads the provided HTML string.
|
|
436
|
+
|
|
437
|
+
Args:
|
|
438
|
+
value: The HTML string to load.
|
|
439
|
+
base_url: The base URL to use when resolving relative URLs within the value.
|
|
440
|
+
|
|
441
|
+
Note:
|
|
442
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
443
|
+
"""
|
|
338
444
|
self._check_mobile_or_mac_platform()
|
|
339
|
-
self.
|
|
445
|
+
asyncio.create_task(self.load_html_async(value, base_url))
|
|
446
|
+
|
|
447
|
+
async def load_html_async(self, value: str, base_url: Optional[str] = None):
|
|
448
|
+
"""
|
|
449
|
+
Loads the provided HTML string.
|
|
450
|
+
|
|
451
|
+
Args:
|
|
452
|
+
value: The HTML string to load.
|
|
453
|
+
base_url: The base URL to use when resolving relative URLs within the value.
|
|
454
|
+
|
|
455
|
+
Note:
|
|
456
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
457
|
+
"""
|
|
458
|
+
self._check_mobile_or_mac_platform()
|
|
459
|
+
await self._invoke_method_async(
|
|
340
460
|
"load_html", arguments={"value": value, "base_url": base_url}
|
|
341
461
|
)
|
|
342
462
|
|
|
343
463
|
def scroll_to(self, x: int, y: int):
|
|
464
|
+
"""
|
|
465
|
+
Scroll to the provided position of webview pixels.
|
|
466
|
+
|
|
467
|
+
Args:
|
|
468
|
+
x: The x-coordinate of the scroll position.
|
|
469
|
+
y: The y-coordinate of the scroll position.
|
|
470
|
+
|
|
471
|
+
Note:
|
|
472
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
473
|
+
"""
|
|
474
|
+
self._check_mobile_or_mac_platform()
|
|
475
|
+
asyncio.create_task(self.scroll_to_async(x, y))
|
|
476
|
+
|
|
477
|
+
async def scroll_to_async(self, x: int, y: int):
|
|
478
|
+
"""
|
|
479
|
+
Scroll to the provided position of webview pixels.
|
|
480
|
+
|
|
481
|
+
Args:
|
|
482
|
+
x: The x-coordinate of the scroll position.
|
|
483
|
+
y: The y-coordinate of the scroll position.
|
|
484
|
+
|
|
485
|
+
Note:
|
|
486
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
487
|
+
"""
|
|
344
488
|
self._check_mobile_or_mac_platform()
|
|
345
|
-
self.
|
|
489
|
+
await self._invoke_method_async("scroll_to", arguments={"x": x, "y": y})
|
|
346
490
|
|
|
347
491
|
def scroll_by(self, x: int, y: int):
|
|
492
|
+
"""
|
|
493
|
+
Scroll by the provided number of webview pixels.
|
|
494
|
+
|
|
495
|
+
Args:
|
|
496
|
+
x: The number of pixels to scroll by on the x-axis.
|
|
497
|
+
y: The number of pixels to scroll by on the y-axis.
|
|
498
|
+
|
|
499
|
+
Note:
|
|
500
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
501
|
+
"""
|
|
348
502
|
self._check_mobile_or_mac_platform()
|
|
349
|
-
self.
|
|
350
|
-
|
|
351
|
-
# bgcolor
|
|
352
|
-
@property
|
|
353
|
-
def bgcolor(self) -> Optional[ColorValue]:
|
|
354
|
-
return self.__bgcolor
|
|
355
|
-
|
|
356
|
-
@bgcolor.setter
|
|
357
|
-
def bgcolor(self, value: Optional[ColorValue]):
|
|
358
|
-
self.__bgcolor = value
|
|
359
|
-
self._set_enum_attr("bgcolor", value, ColorEnums)
|
|
360
|
-
|
|
361
|
-
# url
|
|
362
|
-
@property
|
|
363
|
-
def url(self) -> str:
|
|
364
|
-
return self._get_attr("url")
|
|
365
|
-
|
|
366
|
-
@url.setter
|
|
367
|
-
def url(self, value: str):
|
|
368
|
-
self._set_attr("url", value)
|
|
369
|
-
if self.page:
|
|
370
|
-
self.load_request(value, WebviewRequestMethod.GET)
|
|
371
|
-
|
|
372
|
-
# javascript_enabled
|
|
373
|
-
@property
|
|
374
|
-
def javascript_enabled(self) -> bool:
|
|
375
|
-
warnings.warn(
|
|
376
|
-
f"javascript_enabled is deprecated since version 0.25.0 "
|
|
377
|
-
f"and will be removed in version 0.28.0. Use enable_javascript instead.",
|
|
378
|
-
category=DeprecationWarning,
|
|
379
|
-
stacklevel=2,
|
|
380
|
-
)
|
|
381
|
-
return self._get_attr("javascriptEnabled", data_type="bool", def_value=False)
|
|
382
|
-
|
|
383
|
-
@javascript_enabled.setter
|
|
384
|
-
def javascript_enabled(self, value: Optional[bool]):
|
|
385
|
-
self._set_attr("javascriptEnabled", value)
|
|
386
|
-
if value is not None:
|
|
387
|
-
warnings.warn(
|
|
388
|
-
f"javascript_enabled is deprecated since version 0.25.0 "
|
|
389
|
-
f"and will be removed in version 0.28.0. Use enable_javascript instead.",
|
|
390
|
-
category=DeprecationWarning,
|
|
391
|
-
stacklevel=2,
|
|
392
|
-
)
|
|
393
|
-
if self.page:
|
|
394
|
-
self.invoke_method(
|
|
395
|
-
"set_javascript_mode",
|
|
396
|
-
arguments={"value": str(value)},
|
|
397
|
-
)
|
|
398
|
-
|
|
399
|
-
# enable_javascript
|
|
400
|
-
@property
|
|
401
|
-
def enable_javascript(self) -> bool:
|
|
402
|
-
return self._get_attr("enableJavascript", data_type="bool", def_value=False)
|
|
403
|
-
|
|
404
|
-
@enable_javascript.setter
|
|
405
|
-
def enable_javascript(self, value: Optional[bool]):
|
|
406
|
-
self._set_attr("enableJavascript", value)
|
|
407
|
-
if self.page and value is not None:
|
|
408
|
-
self.invoke_method(
|
|
409
|
-
"set_javascript_mode",
|
|
410
|
-
arguments={"value": str(value)},
|
|
411
|
-
)
|
|
503
|
+
asyncio.create_task(self.scroll_by_async(x, y))
|
|
412
504
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
@on_page_started.setter
|
|
428
|
-
def on_page_started(self, handler: OptionalControlEventCallable):
|
|
429
|
-
self._add_event_handler("page_started", handler)
|
|
430
|
-
|
|
431
|
-
# on_page_ended
|
|
432
|
-
@property
|
|
433
|
-
def on_page_ended(self) -> OptionalControlEventCallable:
|
|
434
|
-
return self._get_event_handler("page_ended")
|
|
435
|
-
|
|
436
|
-
@on_page_ended.setter
|
|
437
|
-
def on_page_ended(self, handler: OptionalControlEventCallable):
|
|
438
|
-
self._add_event_handler("page_ended", handler)
|
|
439
|
-
|
|
440
|
-
# on_web_resource_error
|
|
441
|
-
@property
|
|
442
|
-
def on_web_resource_error(self) -> OptionalControlEventCallable:
|
|
443
|
-
return self._get_event_handler("web_resource_error")
|
|
444
|
-
|
|
445
|
-
@on_web_resource_error.setter
|
|
446
|
-
def on_web_resource_error(self, handler: OptionalControlEventCallable):
|
|
447
|
-
self._add_event_handler("web_resource_error", handler)
|
|
448
|
-
|
|
449
|
-
# on_progress
|
|
450
|
-
@property
|
|
451
|
-
def on_progress(self) -> OptionalControlEventCallable:
|
|
452
|
-
return self._get_event_handler("progress")
|
|
453
|
-
|
|
454
|
-
@on_progress.setter
|
|
455
|
-
def on_progress(self, handler: OptionalControlEventCallable):
|
|
456
|
-
self._add_event_handler("progress", handler)
|
|
457
|
-
|
|
458
|
-
# on_url_change
|
|
459
|
-
@property
|
|
460
|
-
def on_url_change(self) -> OptionalControlEventCallable:
|
|
461
|
-
return self._get_event_handler("url_change")
|
|
462
|
-
|
|
463
|
-
@on_url_change.setter
|
|
464
|
-
def on_url_change(self, handler: OptionalControlEventCallable):
|
|
465
|
-
self._add_event_handler("url_change", handler)
|
|
466
|
-
|
|
467
|
-
# on_scroll
|
|
468
|
-
@property
|
|
469
|
-
def on_scroll(self) -> OptionalEventCallable[WebviewScrollEvent]:
|
|
470
|
-
return self.__on_scroll.handler
|
|
471
|
-
|
|
472
|
-
@on_scroll.setter
|
|
473
|
-
def on_scroll(self, handler: OptionalEventCallable[WebviewScrollEvent]):
|
|
474
|
-
self.__on_scroll.handler = handler
|
|
475
|
-
|
|
476
|
-
# on_console_message
|
|
477
|
-
@property
|
|
478
|
-
def on_console_message(self) -> OptionalEventCallable[WebviewConsoleMessageEvent]:
|
|
479
|
-
return self.__on_console_message.handler
|
|
480
|
-
|
|
481
|
-
@on_console_message.setter
|
|
482
|
-
def on_console_message(
|
|
483
|
-
self, handler: OptionalEventCallable[WebviewConsoleMessageEvent]
|
|
484
|
-
):
|
|
485
|
-
self.__on_console_message.handler = handler
|
|
486
|
-
|
|
487
|
-
# on_javascript_alert_dialog
|
|
488
|
-
@property
|
|
489
|
-
def on_javascript_alert_dialog(
|
|
490
|
-
self,
|
|
491
|
-
) -> OptionalEventCallable[WebviewJavaScriptEvent]:
|
|
492
|
-
return self.__on_javascript_alert_dialog.handler
|
|
493
|
-
|
|
494
|
-
@on_javascript_alert_dialog.setter
|
|
495
|
-
def on_javascript_alert_dialog(
|
|
496
|
-
self, handler: OptionalEventCallable[WebviewJavaScriptEvent]
|
|
497
|
-
):
|
|
498
|
-
self.__on_javascript_alert_dialog.handler = handler
|
|
505
|
+
async def scroll_by_async(self, x: int, y: int):
|
|
506
|
+
"""
|
|
507
|
+
Scroll by the provided number of webview pixels.
|
|
508
|
+
|
|
509
|
+
Args:
|
|
510
|
+
x: The number of pixels to scroll by on the x-axis.
|
|
511
|
+
y: The number of pixels to scroll by on the y-axis.
|
|
512
|
+
|
|
513
|
+
Note:
|
|
514
|
+
Works only on the following platforms: iOS, Android and macOS.
|
|
515
|
+
"""
|
|
516
|
+
self._check_mobile_or_mac_platform()
|
|
517
|
+
await self._invoke_method_async("scroll_by", arguments={"x": x, "y": y})
|