flet-webview 0.2.0.dev49__py3-none-any.whl → 0.2.0.dev66__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 CHANGED
@@ -1,8 +1,19 @@
1
- from .types import (
1
+ from flet_webview.types import (
2
+ JavaScriptMode,
2
3
  LogLevelSeverity,
3
4
  RequestMethod,
4
5
  WebViewConsoleMessageEvent,
5
6
  WebViewJavaScriptEvent,
6
7
  WebViewScrollEvent,
7
8
  )
8
- from .webview import WebView
9
+ from flet_webview.webview import WebView
10
+
11
+ __all__ = [
12
+ "JavaScriptMode",
13
+ "LogLevelSeverity",
14
+ "RequestMethod",
15
+ "WebView",
16
+ "WebViewConsoleMessageEvent",
17
+ "WebViewJavaScriptEvent",
18
+ "WebViewScrollEvent",
19
+ ]
flet_webview/types.py CHANGED
@@ -1,14 +1,19 @@
1
1
  from dataclasses import dataclass
2
2
  from enum import Enum
3
+ from typing import TYPE_CHECKING
3
4
 
4
5
  import flet as ft
5
6
 
7
+ if TYPE_CHECKING:
8
+ from flet_webview.webview import WebView # noqa
9
+
6
10
  __all__ = [
7
- "RequestMethod",
11
+ "JavaScriptMode",
8
12
  "LogLevelSeverity",
9
- "WebViewScrollEvent",
13
+ "RequestMethod",
10
14
  "WebViewConsoleMessageEvent",
11
15
  "WebViewJavaScriptEvent",
16
+ "WebViewScrollEvent",
12
17
  ]
13
18
 
14
19
 
@@ -44,17 +49,33 @@ class LogLevelSeverity(Enum):
44
49
  """Indicates a log message was logged using the `console.log` method."""
45
50
 
46
51
 
52
+ class JavaScriptMode(Enum):
53
+ """Defines the state of JavaScript support in the `WebView`."""
54
+
55
+ UNRESTRICTED = "unrestricted"
56
+ """JavaScript execution is unrestricted."""
57
+
58
+ DISABLED = "disabled"
59
+ """JavaScript execution is disabled."""
60
+
61
+
47
62
  @dataclass
48
- class WebViewScrollEvent(ft.Event[ft.EventControlType]):
63
+ class WebViewScrollEvent(ft.Event["WebView"]):
49
64
  x: float
50
- """The value of the horizontal offset with the origin being at the leftmost of the `WebView`."""
65
+ """
66
+ The value of the horizontal offset with the origin being at the
67
+ leftmost of the `WebView`.
68
+ """
51
69
 
52
70
  y: float
53
- """The value of the vertical offset with the origin being at the topmost of the `WebView`."""
71
+ """
72
+ The value of the vertical offset with the origin being at the
73
+ topmost of the `WebView`.
74
+ """
54
75
 
55
76
 
56
77
  @dataclass
57
- class WebViewConsoleMessageEvent(ft.Event[ft.EventControlType]):
78
+ class WebViewConsoleMessageEvent(ft.Event["WebView"]):
58
79
  message: str
59
80
  """The message written to the console."""
60
81
 
@@ -63,7 +84,7 @@ class WebViewConsoleMessageEvent(ft.Event[ft.EventControlType]):
63
84
 
64
85
 
65
86
  @dataclass
66
- class WebViewJavaScriptEvent(ft.Event[ft.EventControlType]):
87
+ class WebViewJavaScriptEvent(ft.Event["WebView"]):
67
88
  message: str
68
89
  """The message to be displayed in the window."""
69
90
 
flet_webview/webview.py CHANGED
@@ -1,9 +1,9 @@
1
- import asyncio
2
- from typing import List, Optional
1
+ from typing import Optional
3
2
 
4
3
  import flet as ft
5
4
 
6
- from .types import (
5
+ from flet_webview.types import (
6
+ JavaScriptMode,
7
7
  RequestMethod,
8
8
  WebViewConsoleMessageEvent,
9
9
  WebViewJavaScriptEvent,
@@ -25,105 +25,95 @@ class WebView(ft.ConstrainedControl):
25
25
  url: str
26
26
  """The URL of the web page to load."""
27
27
 
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
- """
34
-
35
- prevent_links: Optional[List[str]] = None
28
+ prevent_links: Optional[list[str]] = None
36
29
  """List of url-prefixes that should not be followed/loaded/downloaded."""
37
30
 
38
31
  bgcolor: Optional[ft.ColorValue] = None
39
32
  """Defines the background color of the WebView."""
40
33
 
41
- on_page_started: ft.OptionalControlEventHandler["WebView"] = None
34
+ on_page_started: Optional[ft.ControlEventHandler["WebView"]] = None
42
35
  """
43
36
  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
-
37
+
38
+ Event handler argument's [`data`][flet.Event.data] property is of type
39
+ `str` and contains the URL.
40
+
47
41
  Note:
48
42
  Works only on the following platforms: iOS, Android and macOS.
49
43
  """
50
44
 
51
- on_page_ended: ft.OptionalControlEventHandler["WebView"] = None
45
+ on_page_ended: Optional[ft.ControlEventHandler["WebView"]] = None
52
46
  """
53
47
  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
-
48
+
49
+ Event handler argument's [`data`][flet.Event.data] property is of type `str`
50
+ and contains the URL.
51
+
57
52
  Note:
58
53
  Works only on the following platforms: iOS, Android and macOS.
59
54
  """
60
55
 
61
- on_web_resource_error: ft.OptionalControlEventHandler["WebView"] = None
56
+ on_web_resource_error: Optional[ft.ControlEventHandler["WebView"]] = None
62
57
  """
63
58
  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
-
59
+
60
+ Event handler argument's [`data`][flet.Event.data] property is of type
61
+ `str` and contains the error message.
62
+
67
63
  Note:
68
64
  Works only on the following platforms: iOS, Android and macOS.
69
65
  """
70
66
 
71
- on_progress: ft.OptionalControlEventHandler["WebView"] = None
67
+ on_progress: Optional[ft.ControlEventHandler["WebView"]] = None
72
68
  """
73
69
  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
-
70
+
71
+ Event handler argument's [`data`][flet.Event.data] property is of type
72
+ `int` and contains the progress value.
73
+
77
74
  Note:
78
75
  Works only on the following platforms: iOS, Android and macOS.
79
76
  """
80
77
 
81
- on_url_change: ft.OptionalControlEventHandler["WebView"] = None
78
+ on_url_change: Optional[ft.ControlEventHandler["WebView"]] = None
82
79
  """
83
80
  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
-
81
+
82
+ Event handler argument's [`data`][flet.Event.data] property is of type
83
+ `str` and contains the new URL.
84
+
87
85
  Note:
88
86
  Works only on the following platforms: iOS, Android and macOS.
89
87
  """
90
88
 
91
- on_scroll: ft.OptionalEventHandler[WebViewScrollEvent["WebView"]] = None
89
+ on_scroll: Optional[ft.EventHandler[WebViewScrollEvent]] = None
92
90
  """
93
91
  Fires when the web page's scroll position changes.
94
-
95
- Event handler argument is of type `WebviewScrollEvent`.
96
-
92
+
97
93
  Note:
98
94
  Works only on the following platforms: iOS, Android and macOS.
99
95
  """
100
96
 
101
- on_console_message: ft.OptionalEventHandler[
102
- WebViewConsoleMessageEvent["WebView"]
103
- ] = None
97
+ on_console_message: Optional[ft.EventHandler[WebViewConsoleMessageEvent]] = None
104
98
  """
105
99
  Fires when a log message is written to the JavaScript console.
106
-
107
- Event handler argument is of type `WebviewConsoleMessageEvent`.
108
-
100
+
109
101
  Note:
110
102
  Works only on the following platforms: iOS, Android and macOS.
111
103
  """
112
104
 
113
- on_javascript_alert_dialog: ft.OptionalEventHandler[
114
- WebViewJavaScriptEvent["WebView"]
115
- ] = None
105
+ on_javascript_alert_dialog: Optional[ft.EventHandler[WebViewJavaScriptEvent]] = None
116
106
  """
117
107
  Fires when the web page attempts to display a JavaScript alert() dialog.
118
-
119
- Event handler argument is of type `WebviewJavaScriptEvent`.
120
-
108
+
121
109
  Note:
122
110
  Works only on the following platforms: iOS, Android and macOS.
123
111
  """
124
112
 
125
113
  def _check_mobile_or_mac_platform(self):
126
- """Checks/Validates support for the current platform (iOS, Android, or macOS)."""
114
+ """
115
+ Checks/Validates support for the current platform (iOS, Android, or macOS).
116
+ """
127
117
  assert self.page is not None, "WebView must be added to page first."
128
118
  if self.page.web or self.page.platform not in [
129
119
  ft.PagePlatform.ANDROID,
@@ -134,7 +124,7 @@ class WebView(ft.ConstrainedControl):
134
124
  "This method is supported on Android, iOS and macOS platforms only."
135
125
  )
136
126
 
137
- def reload(self):
127
+ async def reload(self):
138
128
  """
139
129
  Reloads the current URL.
140
130
 
@@ -142,125 +132,76 @@ class WebView(ft.ConstrainedControl):
142
132
  Works only on the following platforms: iOS, Android and macOS.
143
133
  """
144
134
  self._check_mobile_or_mac_platform()
145
- asyncio.create_task(self.reload_async())
135
+ await self._invoke_method("reload")
146
136
 
147
- async def reload_async(self):
137
+ async def can_go_back(self) -> bool:
148
138
  """
149
- Reloads the current URL.
139
+ Whether there's a back history item.
150
140
 
151
141
  Note:
152
142
  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")
156
-
157
- async def can_go_back_async(self) -> bool:
158
- """
159
- Whether there's a back history item.
160
143
 
161
144
  Returns:
162
145
  `True` if there is a back history item, `False` otherwise.
163
-
164
- Note:
165
- Works only on the following platforms: iOS, Android and macOS.
166
146
  """
167
147
  self._check_mobile_or_mac_platform()
168
- return await self._invoke_method_async("can_go_back")
148
+ return await self._invoke_method("can_go_back")
169
149
 
170
150
  async def can_go_forward(self) -> bool:
171
151
  """
172
152
  Whether there's a forward history item.
173
153
 
174
- Returns:
175
- `True` if there is a forward history item, `False` otherwise.
176
-
177
154
  Note:
178
155
  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")
182
-
183
- def go_back(self):
184
- """
185
- Go back in the history of the webview, if `can_go_back()` is `True`.
186
-
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())
192
156
 
193
- async def go_back_async(self):
194
- """
195
- Go back in the history of the webview, if `can_go_back()` is `True`.
196
-
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")
202
-
203
- def go_forward(self):
204
- """
205
- Go forward in the history of the webview, if `can_go_forward()` is `True`.
206
-
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())
212
-
213
- async def go_forward_async(self):
214
- """
215
- Go forward in the history of the webview, if `can_go_forward()` is `True`.
216
-
217
- Note:
218
- Works only on the following platforms: iOS, Android and macOS.
157
+ Returns:
158
+ `True` if there is a forward history item, `False` otherwise.
219
159
  """
220
160
  self._check_mobile_or_mac_platform()
221
- await self._invoke_method_async("go_forward")
161
+ return await self._invoke_method("can_go_forward")
222
162
 
223
- def enable_zoom(self):
163
+ async def go_back(self):
224
164
  """
225
- Enable zooming using the on-screen zoom controls and gestures.
165
+ Goes back in the history of the webview, if `can_go_back()` is `True`.
226
166
 
227
167
  Note:
228
168
  Works only on the following platforms: iOS, Android and macOS.
229
169
  """
230
170
  self._check_mobile_or_mac_platform()
231
- asyncio.create_task(self.enable_zoom_async())
171
+ await self._invoke_method("go_back")
232
172
 
233
- async def enable_zoom_async(self):
173
+ async def go_forward(self):
234
174
  """
235
- Enable zooming using the on-screen zoom controls and gestures.
175
+ Goes forward in the history of the webview,
176
+ if [`can_go_forward()`][(c).can_go_forward] is `True`.
236
177
 
237
178
  Note:
238
179
  Works only on the following platforms: iOS, Android and macOS.
239
180
  """
240
181
  self._check_mobile_or_mac_platform()
241
- await self._invoke_method_async("enable_zoom")
182
+ await self._invoke_method("go_forward")
242
183
 
243
- def disable_zoom(self):
184
+ async def enable_zoom(self):
244
185
  """
245
- Disable zooming using the on-screen zoom controls and gestures.
186
+ Enables zooming using the on-screen zoom controls and gestures.
246
187
 
247
188
  Note:
248
189
  Works only on the following platforms: iOS, Android and macOS.
249
190
  """
250
191
  self._check_mobile_or_mac_platform()
251
- asyncio.create_task(self.disable_zoom_async())
192
+ await self._invoke_method("enable_zoom")
252
193
 
253
- async def disable_zoom_async(self):
194
+ async def disable_zoom(self):
254
195
  """
255
- Disable zooming using the on-screen zoom controls and gestures.
196
+ Disables zooming using the on-screen zoom controls and gestures.
256
197
 
257
198
  Note:
258
199
  Works only on the following platforms: iOS, Android and macOS.
259
200
  """
260
201
  self._check_mobile_or_mac_platform()
261
- await self._invoke_method_async("disable_zoom")
202
+ await self._invoke_method("disable_zoom")
262
203
 
263
- def clear_cache(self):
204
+ async def clear_cache(self):
264
205
  """
265
206
  Clears all caches used by the WebView.
266
207
 
@@ -273,122 +214,76 @@ class WebView(ft.ConstrainedControl):
273
214
  Works only on the following platforms: iOS, Android and macOS.
274
215
  """
275
216
  self._check_mobile_or_mac_platform()
276
- asyncio.create_task(self.clear_cache_async())
217
+ await self._invoke_method("clear_cache")
277
218
 
278
- async def clear_cache_async(self):
219
+ async def clear_local_storage(self):
279
220
  """
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
221
+ Clears the local storage used by the WebView.
286
222
 
287
223
  Note:
288
224
  Works only on the following platforms: iOS, Android and macOS.
289
225
  """
290
226
  self._check_mobile_or_mac_platform()
291
- await self._invoke_method_async("clear_cache")
227
+ await self._invoke_method("clear_local_storage")
292
228
 
293
- def clear_local_storage(self):
229
+ async def get_current_url(self) -> Optional[str]:
294
230
  """
295
- Clears the local storage used by the WebView.
231
+ Gets the current URL that the WebView is displaying or `None`
232
+ if no URL was ever loaded.
296
233
 
297
234
  Note:
298
235
  Works only on the following platforms: iOS, Android and macOS.
236
+
237
+ Returns:
238
+ The current URL that the WebView is displaying or `None`
239
+ if no URL was ever loaded.
299
240
  """
300
241
  self._check_mobile_or_mac_platform()
301
- asyncio.create_task(self.clear_local_storage_async())
242
+ return await self._invoke_method("get_current_url")
302
243
 
303
- async def clear_local_storage_async(self):
244
+ async def get_title(self) -> Optional[str]:
304
245
  """
305
- Clears the local storage used by the WebView.
246
+ Get the title of the currently loaded page.
306
247
 
307
248
  Note:
308
249
  Works only on the following platforms: iOS, Android and macOS.
309
- """
310
- self._check_mobile_or_mac_platform()
311
- await self._invoke_method_async("clear_local_storage")
312
-
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
250
 
317
251
  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.
252
+ The title of the currently loaded page.
322
253
  """
323
254
  self._check_mobile_or_mac_platform()
324
- return await self._invoke_method_async("get_current_url")
255
+ return await self._invoke_method("get_title")
325
256
 
326
- async def get_title_async(self) -> Optional[str]:
257
+ async def get_user_agent(self) -> Optional[str]:
327
258
  """
328
- Returns the title of the currently loaded page.
329
-
330
- Returns:
331
- The title of the currently loaded page.
259
+ Get the value used for the HTTP `User-Agent:` request header.
332
260
 
333
261
  Note:
334
262
  Works only on the following platforms: iOS, Android and macOS.
335
- """
336
- self._check_mobile_or_mac_platform()
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.
342
263
 
343
264
  Returns:
344
265
  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
266
  """
349
267
  self._check_mobile_or_mac_platform()
350
- return await self._invoke_method_async("get_user_agent")
268
+ return await self._invoke_method("get_user_agent")
351
269
 
352
- def load_file(self, path: str):
270
+ async def load_file(self, path: str):
353
271
  """
354
272
  Loads the provided local file.
355
273
 
356
- Args:
357
- path: The absolute path to the file.
358
-
359
274
  Note:
360
275
  Works only on the following platforms: iOS, Android and macOS.
361
- """
362
- self._check_mobile_or_mac_platform()
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.
368
276
 
369
277
  Args:
370
278
  path: The absolute path to the file.
371
-
372
- Note:
373
- Works only on the following platforms: iOS, Android and macOS.
374
- """
375
- self._check_mobile_or_mac_platform()
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.
381
-
382
- Args:
383
- url: The URL to load.
384
- method: The HTTP method to use.
385
279
  """
386
280
  self._check_mobile_or_mac_platform()
387
- asyncio.create_task(self.load_request_async(url, method))
281
+ await self._invoke_method(
282
+ method_name="load_file",
283
+ arguments={"path": path},
284
+ )
388
285
 
389
- async def load_request_async(
390
- self, url: str, method: RequestMethod = RequestMethod.GET
391
- ):
286
+ async def load_request(self, url: str, method: RequestMethod = RequestMethod.GET):
392
287
  """
393
288
  Makes an HTTP request and loads the response in the webview.
394
289
 
@@ -400,24 +295,11 @@ class WebView(ft.ConstrainedControl):
400
295
  Works only on the following platforms: iOS, Android and macOS.
401
296
  """
402
297
  self._check_mobile_or_mac_platform()
403
- await self._invoke_method_async(
298
+ await self._invoke_method(
404
299
  "load_request", arguments={"url": url, "method": method}
405
300
  )
406
301
 
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):
302
+ async def run_javascript(self, value: str):
421
303
  """
422
304
  Runs the given JavaScript in the context of the current page.
423
305
 
@@ -428,90 +310,75 @@ class WebView(ft.ConstrainedControl):
428
310
  Works only on the following platforms: iOS, Android and macOS.
429
311
  """
430
312
  self._check_mobile_or_mac_platform()
431
- await self._invoke_method_async("run_javascript", arguments={"value": value})
313
+ await self._invoke_method(
314
+ method_name="run_javascript",
315
+ arguments={"value": value},
316
+ )
432
317
 
433
- def load_html(self, value: str, base_url: Optional[str] = None):
318
+ async def load_html(self, value: str, base_url: Optional[str] = None):
434
319
  """
435
320
  Loads the provided HTML string.
436
321
 
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
322
  Note:
442
323
  Works only on the following platforms: iOS, Android and macOS.
443
- """
444
- self._check_mobile_or_mac_platform()
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
324
 
451
325
  Args:
452
326
  value: The HTML string to load.
453
327
  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
328
  """
458
329
  self._check_mobile_or_mac_platform()
459
- await self._invoke_method_async(
330
+ await self._invoke_method(
460
331
  "load_html", arguments={"value": value, "base_url": base_url}
461
332
  )
462
333
 
463
- def scroll_to(self, x: int, y: int):
334
+ async def scroll_to(self, x: int, y: int):
464
335
  """
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.
336
+ Scrolls to the provided position of webview pixels.
470
337
 
471
338
  Note:
472
339
  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
340
 
481
341
  Args:
482
342
  x: The x-coordinate of the scroll position.
483
343
  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
345
  self._check_mobile_or_mac_platform()
489
- await self._invoke_method_async("scroll_to", arguments={"x": x, "y": y})
346
+ await self._invoke_method(
347
+ method_name="scroll_to",
348
+ arguments={"x": x, "y": y},
349
+ )
490
350
 
491
- def scroll_by(self, x: int, y: int):
351
+ async def scroll_by(self, x: int, y: int):
492
352
  """
493
- Scroll by the provided number of webview pixels.
353
+ Scrolls by the provided number of webview pixels.
354
+
355
+ Note:
356
+ Works only on the following platforms: iOS, Android and macOS.
494
357
 
495
358
  Args:
496
359
  x: The number of pixels to scroll by on the x-axis.
497
360
  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
361
  """
502
362
  self._check_mobile_or_mac_platform()
503
- asyncio.create_task(self.scroll_by_async(x, y))
363
+ await self._invoke_method(
364
+ method_name="scroll_by",
365
+ arguments={"x": x, "y": y},
366
+ )
504
367
 
505
- async def scroll_by_async(self, x: int, y: int):
368
+ async def set_javascript_mode(self, mode: JavaScriptMode):
506
369
  """
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.
370
+ Sets the JavaScript mode of the WebView.
512
371
 
513
372
  Note:
514
- Works only on the following platforms: iOS, Android and macOS.
373
+ - Works only on the following platforms: iOS, Android and macOS.
374
+ - Disabling the JavaScript execution on the page may result to
375
+ unexpected web page behaviour.
376
+
377
+ Args:
378
+ mode: The JavaScript mode to set.
515
379
  """
516
380
  self._check_mobile_or_mac_platform()
517
- await self._invoke_method_async("scroll_by", arguments={"x": x, "y": y})
381
+ await self._invoke_method(
382
+ method_name="set_javascript_mode",
383
+ arguments={"mode": mode},
384
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flet-webview
3
- Version: 0.2.0.dev49
3
+ Version: 0.2.0.dev66
4
4
  Summary: Display web content in Flet apps using WebView.
5
5
  Author-email: Flet contributors <hello@flet.dev>
6
6
  License-Expression: Apache-2.0
@@ -42,7 +42,9 @@ This package supports the following platforms:
42
42
  | Android | ✅ |
43
43
  | Web | ✅ |
44
44
 
45
- ## Installation
45
+ ## Usage
46
+
47
+ ### Installation
46
48
 
47
49
  To install the `flet-webview` package and add it to your project dependencies:
48
50
 
@@ -62,6 +64,6 @@ To install the `flet-webview` package and add it to your project dependencies:
62
64
  poetry add flet-webview
63
65
  ```
64
66
 
65
- ## Examples
67
+ ### Examples
66
68
 
67
- For examples, see [this](./examples)
69
+ For examples, see [these](./examples).
@@ -1,23 +1,23 @@
1
- flet_webview/__init__.py,sha256=n436xnrBEfTS9u5IHrcOnuVT_G3trLDsBFxNuIvgcIY,177
2
- flet_webview/types.py,sha256=ZZ_ES4AXnL5ucHC_pmTsUFU90EZaQrhpUje5niC1ox4,1807
3
- flet_webview/webview.py,sha256=_lyHJoxzbUGEvkWce4TvUmYYmhhu_d0zzZvXM6o6Rnw,16440
4
- flet_webview-0.2.0.dev49.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1
+ flet_webview/__init__.py,sha256=OK4CdtkxGRYvBiIuNEVr_zXw8sSNI29v8lRqKtI_im0,408
2
+ flet_webview/types.py,sha256=PmI84y3ZTa0AVEffW-VlYHQXW1JcHAvczfrYnR9cmP0,2184
3
+ flet_webview/webview.py,sha256=n6BL8mqvNhacC2xId8kEVId5bhMjcBePzlV9WH7qjeE,11832
4
+ flet_webview-0.2.0.dev66.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
5
  flutter/flet_webview/CHANGELOG.md,sha256=66sWepPaeTc9_lzcYIGU55AlxSU5Z1XVtknXpzd_-p8,40
6
6
  flutter/flet_webview/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
7
7
  flutter/flet_webview/README.md,sha256=GIdqSwI5CZ6a1JQad87qfn_zGBRL2hPB6nTgB2PtuaU,64
8
8
  flutter/flet_webview/analysis_options.yaml,sha256=32kjGAc-zF87inWaH5M46yGZWQDTwrwfvNLHeAocfG4,154
9
- flutter/flet_webview/pubspec.lock,sha256=usi3ZkL1SEvDqJkAWj1eDhWnCZuH9HY1o5k0GNEAuFY,24121
10
- flutter/flet_webview/pubspec.yaml,sha256=l6EJNWjZWAt6mr8HS2R85dYyTNo3qJk7gcW_1O-njQM,641
9
+ flutter/flet_webview/pubspec.lock,sha256=TngFTZNx6UdpktW6li9FLO9IukASDRkbuxR3nWZt_NQ,24579
10
+ flutter/flet_webview/pubspec.yaml,sha256=5atkJMd8GycvAiSzZJIC7YKGMF9BXnwIiGmjKxMHLZM,641
11
11
  flutter/flet_webview/lib/flet_webview.dart,sha256=aB3uPJrudP8SaZfpr2GH3c3j2jEZcEIeGrAkFiXb9IA,67
12
12
  flutter/flet_webview/lib/src/extension.dart,sha256=lff3mOfxO2_Ite2Oi5VAoHD42BGrN3N4hjF0rGuPv3s,350
13
13
  flutter/flet_webview/lib/src/webview.dart,sha256=HrcXyQv_rVuun0szbEUEFloKSARLy54c78L9gpK6RIA,975
14
- flutter/flet_webview/lib/src/webview_mobile_and_mac.dart,sha256=JiQhpTf5BxaRme8B1-rbkk_N7XiWFEeLYwBF2Fsi5oI,5854
14
+ flutter/flet_webview/lib/src/webview_mobile_and_mac.dart,sha256=KoAxgothe7de_jUfFW_zjj-C8trZjQ5NqcRenHlcvlc,5789
15
15
  flutter/flet_webview/lib/src/webview_web.dart,sha256=MuLZR9soUyKqDdDAYA09d8AzmX00YeT0Pqs3Nbo4Hts,1073
16
16
  flutter/flet_webview/lib/src/webview_web_vain.dart,sha256=Asu8QRq7Fky8MDEdKcOa01ux06j64xK4MwCGa5yvSDU,337
17
17
  flutter/flet_webview/lib/src/webview_windows_and_linux.dart,sha256=LxkO6qbz0aaZM9UYSufUCjrNr1pK12pwlqutH4_-aio,314
18
18
  flutter/flet_webview/lib/src/webview_windows_and_linux_vain.dart,sha256=pF5i1Tqy6avqSiwpqAoIEr98Z7y3ZE_HOrAThhIF86A,452
19
- flutter/flet_webview/lib/src/utils/webview.dart,sha256=s-1UY7kFIzeMRBO_a_XQA1B8YIRxPDIBAmB5Fnw6Fe4,380
20
- flet_webview-0.2.0.dev49.dist-info/METADATA,sha256=hpi5ypkBpjFueL39sIZaf4DBgLpE9zZ-hBPvMnJNuG8,2043
21
- flet_webview-0.2.0.dev49.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
- flet_webview-0.2.0.dev49.dist-info/top_level.txt,sha256=svOnOxqAYWBe87-fr3VmmQm8S73eVhAu0t9O3MryqS4,21
23
- flet_webview-0.2.0.dev49.dist-info/RECORD,,
19
+ flutter/flet_webview/lib/src/utils/webview.dart,sha256=hPbqSfFsQaYyvdmhXesnV1WBHquiRv-SR4RwjPPJqXg,648
20
+ flet_webview-0.2.0.dev66.dist-info/METADATA,sha256=5TyXsT2cqcjTcesmf0GqbtUbCtyOkuOFGXYumZ6iw0M,2057
21
+ flet_webview-0.2.0.dev66.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
+ flet_webview-0.2.0.dev66.dist-info/top_level.txt,sha256=svOnOxqAYWBe87-fr3VmmQm8S73eVhAu0t9O3MryqS4,21
23
+ flet_webview-0.2.0.dev66.dist-info/RECORD,,
@@ -8,3 +8,11 @@ LoadRequestMethod? parseLoadRequestMethod(String? value,
8
8
  (e) => e.name.toLowerCase() == value.toLowerCase()) ??
9
9
  defaultValue;
10
10
  }
11
+
12
+ JavaScriptMode? parseJavaScriptMode(String? value,
13
+ [JavaScriptMode? defaultValue]) {
14
+ if (value == null) return defaultValue;
15
+ return JavaScriptMode.values.firstWhereOrNull(
16
+ (e) => e.name.toLowerCase() == value.toLowerCase()) ??
17
+ defaultValue;
18
+ }
@@ -154,10 +154,9 @@ class _WebviewMobileAndMacState extends State<WebviewMobileAndMac> {
154
154
  }
155
155
  break;
156
156
  case "set_javascript_mode":
157
- var value = parseBool(args["value"]);
158
- if (value != null) {
159
- await controller.setJavaScriptMode(
160
- value ? JavaScriptMode.unrestricted : JavaScriptMode.disabled);
157
+ var mode = parseJavaScriptMode(args["mode"]);
158
+ if (mode != null) {
159
+ await controller.setJavaScriptMode(mode);
161
160
  }
162
161
  break;
163
162
  default:
@@ -13,10 +13,10 @@ packages:
13
13
  dependency: transitive
14
14
  description:
15
15
  name: async
16
- sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
16
+ sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb"
17
17
  url: "https://pub.dev"
18
18
  source: hosted
19
- version: "2.12.0"
19
+ version: "2.13.0"
20
20
  boolean_selector:
21
21
  dependency: transitive
22
22
  description:
@@ -65,6 +65,14 @@ packages:
65
65
  url: "https://pub.dev"
66
66
  source: hosted
67
67
  version: "3.0.6"
68
+ dbus:
69
+ dependency: transitive
70
+ description:
71
+ name: dbus
72
+ sha256: "79e0c23480ff85dc68de79e2cd6334add97e48f7f4865d17686dd6ea81a47e8c"
73
+ url: "https://pub.dev"
74
+ source: hosted
75
+ version: "0.7.11"
68
76
  device_info_plus:
69
77
  dependency: transitive
70
78
  description:
@@ -93,10 +101,10 @@ packages:
93
101
  dependency: transitive
94
102
  description:
95
103
  name: fake_async
96
- sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
104
+ sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
97
105
  url: "https://pub.dev"
98
106
  source: hosted
99
- version: "1.3.2"
107
+ version: "1.3.3"
100
108
  ffi:
101
109
  dependency: transitive
102
110
  description:
@@ -117,16 +125,16 @@ packages:
117
125
  dependency: transitive
118
126
  description:
119
127
  name: file_picker
120
- sha256: ef9908739bdd9c476353d6adff72e88fd00c625f5b959ae23f7567bd5137db0a
128
+ sha256: ef7d2a085c1b1d69d17b6842d0734aad90156de08df6bd3c12496d0bd6ddf8e2
121
129
  url: "https://pub.dev"
122
130
  source: hosted
123
- version: "10.2.0"
131
+ version: "10.3.1"
124
132
  flet:
125
133
  dependency: "direct main"
126
134
  description:
127
135
  path: "packages/flet"
128
136
  ref: main
129
- resolved-ref: b996d06ff462b88f5b31d6cceafac34ea6f57968
137
+ resolved-ref: "4ea9558543657d31dba3b11d6017beed2e16d447"
130
138
  url: "https://github.com/flet-dev/flet.git"
131
139
  source: git
132
140
  version: "0.70.0"
@@ -147,10 +155,10 @@ packages:
147
155
  dependency: "direct dev"
148
156
  description:
149
157
  name: flutter_lints
150
- sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
158
+ sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
151
159
  url: "https://pub.dev"
152
160
  source: hosted
153
- version: "2.0.3"
161
+ version: "3.0.2"
154
162
  flutter_localizations:
155
163
  dependency: transitive
156
164
  description: flutter
@@ -168,10 +176,10 @@ packages:
168
176
  dependency: transitive
169
177
  description:
170
178
  name: flutter_plugin_android_lifecycle
171
- sha256: f948e346c12f8d5480d2825e03de228d0eb8c3a737e4cdaa122267b89c022b5e
179
+ sha256: "6382ce712ff69b0f719640ce957559dde459e55ecd433c767e06d139ddf16cab"
172
180
  url: "https://pub.dev"
173
181
  source: hosted
174
- version: "2.0.28"
182
+ version: "2.0.29"
175
183
  flutter_svg:
176
184
  dependency: transitive
177
185
  description:
@@ -218,10 +226,10 @@ packages:
218
226
  dependency: transitive
219
227
  description:
220
228
  name: intl
221
- sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
229
+ sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
222
230
  url: "https://pub.dev"
223
231
  source: hosted
224
- version: "0.19.0"
232
+ version: "0.20.2"
225
233
  json_annotation:
226
234
  dependency: transitive
227
235
  description:
@@ -234,10 +242,10 @@ packages:
234
242
  dependency: transitive
235
243
  description:
236
244
  name: leak_tracker
237
- sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
245
+ sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
238
246
  url: "https://pub.dev"
239
247
  source: hosted
240
- version: "10.0.8"
248
+ version: "10.0.9"
241
249
  leak_tracker_flutter_testing:
242
250
  dependency: transitive
243
251
  description:
@@ -258,10 +266,10 @@ packages:
258
266
  dependency: transitive
259
267
  description:
260
268
  name: lints
261
- sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
269
+ sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
262
270
  url: "https://pub.dev"
263
271
  source: hosted
264
- version: "2.1.1"
272
+ version: "3.0.0"
265
273
  logging:
266
274
  dependency: transitive
267
275
  description:
@@ -354,10 +362,10 @@ packages:
354
362
  dependency: transitive
355
363
  description:
356
364
  name: path_provider_foundation
357
- sha256: "4843174df4d288f5e29185bd6e72a6fbdf5a4a4602717eed565497429f179942"
365
+ sha256: "16eef174aacb07e09c351502740fa6254c165757638eba1e9116b0a781201bbd"
358
366
  url: "https://pub.dev"
359
367
  source: hosted
360
- version: "2.4.1"
368
+ version: "2.4.2"
361
369
  path_provider_linux:
362
370
  dependency: transitive
363
371
  description:
@@ -454,14 +462,22 @@ packages:
454
462
  url: "https://pub.dev"
455
463
  source: hosted
456
464
  version: "0.2.0"
465
+ screenshot:
466
+ dependency: transitive
467
+ description:
468
+ name: screenshot
469
+ sha256: "63817697a7835e6ce82add4228e15d233b74d42975c143ad8cfe07009fab866b"
470
+ url: "https://pub.dev"
471
+ source: hosted
472
+ version: "3.0.0"
457
473
  sensors_plus:
458
474
  dependency: transitive
459
475
  description:
460
476
  name: sensors_plus
461
- sha256: "905282c917c6bb731c242f928665c2ea15445aa491249dea9d98d7c79dc8fd39"
477
+ sha256: "89e2bfc3d883743539ce5774a2b93df61effde40ff958ecad78cd66b1a8b8d52"
462
478
  url: "https://pub.dev"
463
479
  source: hosted
464
- version: "6.1.1"
480
+ version: "6.1.2"
465
481
  sensors_plus_platform_interface:
466
482
  dependency: transitive
467
483
  description:
@@ -482,10 +498,10 @@ packages:
482
498
  dependency: transitive
483
499
  description:
484
500
  name: shared_preferences_android
485
- sha256: "20cbd561f743a342c76c151d6ddb93a9ce6005751e7aa458baad3858bfbfb6ac"
501
+ sha256: "5bcf0772a761b04f8c6bf814721713de6f3e5d9d89caf8d3fe031b02a342379e"
486
502
  url: "https://pub.dev"
487
503
  source: hosted
488
- version: "2.4.10"
504
+ version: "2.4.11"
489
505
  shared_preferences_foundation:
490
506
  dependency: transitive
491
507
  description:
@@ -599,18 +615,18 @@ packages:
599
615
  dependency: transitive
600
616
  description:
601
617
  name: url_launcher_android
602
- sha256: "8582d7f6fe14d2652b4c45c9b6c14c0b678c2af2d083a11b604caeba51930d79"
618
+ sha256: "0aedad096a85b49df2e4725fa32118f9fa580f3b14af7a2d2221896a02cd5656"
603
619
  url: "https://pub.dev"
604
620
  source: hosted
605
- version: "6.3.16"
621
+ version: "6.3.17"
606
622
  url_launcher_ios:
607
623
  dependency: transitive
608
624
  description:
609
625
  name: url_launcher_ios
610
- sha256: "7f2022359d4c099eea7df3fdf739f7d3d3b9faf3166fb1dd390775176e0b76cb"
626
+ sha256: d80b3f567a617cb923546034cc94bfe44eb15f989fe670b37f26abdb9d939cb7
611
627
  url: "https://pub.dev"
612
628
  source: hosted
613
- version: "6.3.3"
629
+ version: "6.3.4"
614
630
  url_launcher_linux:
615
631
  dependency: transitive
616
632
  description:
@@ -623,10 +639,10 @@ packages:
623
639
  dependency: transitive
624
640
  description:
625
641
  name: url_launcher_macos
626
- sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2"
642
+ sha256: c043a77d6600ac9c38300567f33ef12b0ef4f4783a2c1f00231d2b1941fea13f
627
643
  url: "https://pub.dev"
628
644
  source: hosted
629
- version: "3.2.2"
645
+ version: "3.2.3"
630
646
  url_launcher_platform_interface:
631
647
  dependency: transitive
632
648
  description:
@@ -671,10 +687,10 @@ packages:
671
687
  dependency: transitive
672
688
  description:
673
689
  name: vector_graphics_compiler
674
- sha256: "557a315b7d2a6dbb0aaaff84d857967ce6bdc96a63dc6ee2a57ce5a6ee5d3331"
690
+ sha256: ca81fdfaf62a5ab45d7296614aea108d2c7d0efca8393e96174bf4d51e6725b0
675
691
  url: "https://pub.dev"
676
692
  source: hosted
677
- version: "1.1.17"
693
+ version: "1.1.18"
678
694
  vector_math:
679
695
  dependency: transitive
680
696
  description:
@@ -687,10 +703,10 @@ packages:
687
703
  dependency: transitive
688
704
  description:
689
705
  name: vm_service
690
- sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
706
+ sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
691
707
  url: "https://pub.dev"
692
708
  source: hosted
693
- version: "14.3.1"
709
+ version: "15.0.0"
694
710
  web:
695
711
  dependency: transitive
696
712
  description:
@@ -727,18 +743,18 @@ packages:
727
743
  dependency: transitive
728
744
  description:
729
745
  name: webview_flutter_android
730
- sha256: f6e6afef6e234801da77170f7a1847ded8450778caf2fe13979d140484be3678
746
+ sha256: "0a42444056b24ed832bdf3442d65c5194f6416f7e782152384944053c2ecc9a3"
731
747
  url: "https://pub.dev"
732
748
  source: hosted
733
- version: "4.7.0"
749
+ version: "4.10.0"
734
750
  webview_flutter_platform_interface:
735
751
  dependency: "direct main"
736
752
  description:
737
753
  name: webview_flutter_platform_interface
738
- sha256: f0dc2dc3a2b1e3a6abdd6801b9355ebfeb3b8f6cde6b9dc7c9235909c4a1f147
754
+ sha256: "63d26ee3aca7256a83ccb576a50272edd7cfc80573a4305caa98985feb493ee0"
739
755
  url: "https://pub.dev"
740
756
  source: hosted
741
- version: "2.13.1"
757
+ version: "2.14.0"
742
758
  webview_flutter_web:
743
759
  dependency: "direct main"
744
760
  description:
@@ -751,18 +767,18 @@ packages:
751
767
  dependency: transitive
752
768
  description:
753
769
  name: webview_flutter_wkwebview
754
- sha256: a3d461fe3467014e05f3ac4962e5fdde2a4bf44c561cb53e9ae5c586600fdbc3
770
+ sha256: fb46db8216131a3e55bcf44040ca808423539bc6732e7ed34fb6d8044e3d512f
755
771
  url: "https://pub.dev"
756
772
  source: hosted
757
- version: "3.22.0"
773
+ version: "3.23.0"
758
774
  win32:
759
775
  dependency: transitive
760
776
  description:
761
777
  name: win32
762
- sha256: "329edf97fdd893e0f1e3b9e88d6a0e627128cc17cc316a8d67fda8f1451178ba"
778
+ sha256: "66814138c3562338d05613a6e368ed8cfb237ad6d64a9e9334be3f309acfca03"
763
779
  url: "https://pub.dev"
764
780
  source: hosted
765
- version: "5.13.0"
781
+ version: "5.14.0"
766
782
  win32_registry:
767
783
  dependency: transitive
768
784
  description:
@@ -775,10 +791,10 @@ packages:
775
791
  dependency: transitive
776
792
  description:
777
793
  name: window_manager
778
- sha256: "51d50168ab267d344b975b15390426b1243600d436770d3f13de67e55b05ec16"
794
+ sha256: "7eb6d6c4164ec08e1bf978d6e733f3cebe792e2a23fb07cbca25c2872bfdbdcd"
779
795
  url: "https://pub.dev"
780
796
  source: hosted
781
- version: "0.5.0"
797
+ version: "0.5.1"
782
798
  window_to_front:
783
799
  dependency: transitive
784
800
  description:
@@ -804,5 +820,5 @@ packages:
804
820
  source: hosted
805
821
  version: "6.5.0"
806
822
  sdks:
807
- dart: ">=3.7.0 <4.0.0"
823
+ dart: ">=3.8.0 <4.0.0"
808
824
  flutter: ">=3.29.0"
@@ -24,4 +24,4 @@ dependencies:
24
24
  dev_dependencies:
25
25
  flutter_test:
26
26
  sdk: flutter
27
- flutter_lints: ^2.0.0
27
+ flutter_lints: ^3.0.0