Skip to content

Commit dd3bc61

Browse files
authored
[desktop_webview_window] add support for getting cookies (MixinNetwork#349)
* feat(macos): add support for grabbing cookies * feat(windows): add support for grabbing cookies * feat(linux): ability to grab cookies (incomplete) * feat(linux): ability to grab cookies (limited: only for active websites) * docks: add linux libsoup3 dependency in README * chore: fix some cookie parameters being null causing exceptions
1 parent 726d828 commit dd3bc61

24 files changed

+956
-427
lines changed

packages/desktop_webview_window/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@
2929
build/
3030

3131
.fvm
32+
33+
.vscode

packages/desktop_webview_window/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ Show a webview window on your flutter desktop application.
3939

4040
## linux requirement
4141

42+
In Ubuntu/Debian:
4243
```shell
43-
sudo apt-get install webkit2gtk4.1
44+
sudo apt-get install libwebkit2gtk-4.1-0 libwebkit2gtk-4.1-dev libsoup-3.0-0 libsoup-3.0-dev
45+
```
46+
47+
In Fedora/RPM:
48+
```shell
49+
sudo dnf install webkit2gtk4.1 webkit2gtk4.1-devel libsoup3 libsoup3-devel
4450
```
4551

4652
## Windows

packages/desktop_webview_window/example/lib/main.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:io';
23

34
import 'package:desktop_webview_window/desktop_webview_window.dart';
@@ -63,6 +64,7 @@ class _MyAppState extends State<MyApp> {
6364
userDataFolderWindows: await _getWebViewPath(),
6465
),
6566
);
67+
6668
webview
6769
..registerJavaScriptMessageHandler("test", (name, body) {
6870
debugPrint('on javaScipt message: $name $body');
@@ -134,6 +136,24 @@ class _MyAppState extends State<MyApp> {
134136
titleBarTopPadding: Platform.isMacOS ? 20 : 0,
135137
),
136138
);
139+
140+
final timer = Timer.periodic(const Duration(seconds: 1), (timer) async {
141+
try {
142+
final cookies = await webview.getAllCookies();
143+
144+
if (cookies.isEmpty) {
145+
debugPrint('⚠️ no cookies found');
146+
}
147+
148+
for (final cookie in cookies) {
149+
debugPrint('cookie: ${cookie.toJson()}');
150+
}
151+
} catch (e, stack) {
152+
debugPrint('getAllCookies error: $e');
153+
debugPrintStack(stackTrace: stack);
154+
}
155+
});
156+
137157
webview
138158
..setBrightness(Brightness.dark)
139159
..setApplicationNameForUserAgent(" WebviewExample/1.0.0")
@@ -148,8 +168,10 @@ class _MyAppState extends State<MyApp> {
148168
// grant navigation request
149169
return true;
150170
})
171+
..openDevToolsWindow()
151172
..onClose.whenComplete(() {
152173
debugPrint("on close");
174+
timer.cancel();
153175
});
154176
await Future.delayed(const Duration(seconds: 2));
155177
for (final javaScript in _javaScriptToEval) {

packages/desktop_webview_window/example/macos/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
platform :osx, '10.12'
1+
platform :osx, '10.14'
22

33
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
44
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

packages/desktop_webview_window/example/macos/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ EXTERNAL SOURCES:
1919
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
2020

2121
SPEC CHECKSUMS:
22-
desktop_webview_window: d4365e71bcd4e1aa0c14cf0377aa24db0c16a7e2
22+
desktop_webview_window: 89bb3d691f4c80314a10be312f4cd35db93a9d5a
2323
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
2424
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
2525

26-
PODFILE CHECKSUM: c7161fcf45d4fd9025dc0f48a76d6e64e52f8176
26+
PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7
2727

28-
COCOAPODS: 1.12.1
28+
COCOAPODS: 1.15.2

packages/desktop_webview_window/example/macos/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
isa = PBXProject;
203203
attributes = {
204204
LastSwiftUpdateCheck = 0920;
205-
LastUpgradeCheck = 1430;
205+
LastUpgradeCheck = 1510;
206206
ORGANIZATIONNAME = "";
207207
TargetAttributes = {
208208
33CC10EC2044A3C60003C045 = {
@@ -426,7 +426,7 @@
426426
"$(inherited)",
427427
"@executable_path/../Frameworks",
428428
);
429-
MACOSX_DEPLOYMENT_TARGET = 10.12;
429+
MACOSX_DEPLOYMENT_TARGET = 10.14;
430430
PROVISIONING_PROFILE_SPECIFIER = "";
431431
SWIFT_VERSION = 5.0;
432432
};
@@ -553,7 +553,7 @@
553553
"$(inherited)",
554554
"@executable_path/../Frameworks",
555555
);
556-
MACOSX_DEPLOYMENT_TARGET = 10.12;
556+
MACOSX_DEPLOYMENT_TARGET = 10.14;
557557
PROVISIONING_PROFILE_SPECIFIER = "";
558558
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
559559
SWIFT_VERSION = 5.0;
@@ -574,7 +574,7 @@
574574
"$(inherited)",
575575
"@executable_path/../Frameworks",
576576
);
577-
MACOSX_DEPLOYMENT_TARGET = 10.12;
577+
MACOSX_DEPLOYMENT_TARGET = 10.14;
578578
PROVISIONING_PROFILE_SPECIFIER = "";
579579
SWIFT_VERSION = 5.0;
580580
};

packages/desktop_webview_window/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1430"
3+
LastUpgradeVersion = "1510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

packages/desktop_webview_window/example/pubspec.lock

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ packages:
5555
path: ".."
5656
relative: true
5757
source: path
58-
version: "0.2.3"
58+
version: "0.2.4"
5959
fake_async:
6060
dependency: transitive
6161
description:
@@ -98,6 +98,30 @@ packages:
9898
description: flutter
9999
source: sdk
100100
version: "0.0.0"
101+
leak_tracker:
102+
dependency: transitive
103+
description:
104+
name: leak_tracker
105+
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
106+
url: "https://pub.dev"
107+
source: hosted
108+
version: "10.0.0"
109+
leak_tracker_flutter_testing:
110+
dependency: transitive
111+
description:
112+
name: leak_tracker_flutter_testing
113+
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
114+
url: "https://pub.dev"
115+
source: hosted
116+
version: "2.0.1"
117+
leak_tracker_testing:
118+
dependency: transitive
119+
description:
120+
name: leak_tracker_testing
121+
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
122+
url: "https://pub.dev"
123+
source: hosted
124+
version: "2.0.1"
101125
lints:
102126
dependency: transitive
103127
description:
@@ -110,34 +134,34 @@ packages:
110134
dependency: transitive
111135
description:
112136
name: matcher
113-
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
137+
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
114138
url: "https://pub.dev"
115139
source: hosted
116-
version: "0.12.16"
140+
version: "0.12.16+1"
117141
material_color_utilities:
118142
dependency: transitive
119143
description:
120144
name: material_color_utilities
121-
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
145+
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
122146
url: "https://pub.dev"
123147
source: hosted
124-
version: "0.5.0"
148+
version: "0.8.0"
125149
meta:
126150
dependency: transitive
127151
description:
128152
name: meta
129-
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
153+
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
130154
url: "https://pub.dev"
131155
source: hosted
132-
version: "1.9.1"
156+
version: "1.11.0"
133157
path:
134158
dependency: transitive
135159
description:
136160
name: path
137-
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
161+
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
138162
url: "https://pub.dev"
139163
source: hosted
140-
version: "1.8.3"
164+
version: "1.9.0"
141165
path_provider:
142166
dependency: "direct main"
143167
description:
@@ -279,14 +303,14 @@ packages:
279303
url: "https://pub.dev"
280304
source: hosted
281305
version: "2.1.4"
282-
web:
306+
vm_service:
283307
dependency: transitive
284308
description:
285-
name: web
286-
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
309+
name: vm_service
310+
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
287311
url: "https://pub.dev"
288312
source: hosted
289-
version: "0.1.4-beta"
313+
version: "13.0.0"
290314
win32:
291315
dependency: transitive
292316
description:
@@ -304,5 +328,5 @@ packages:
304328
source: hosted
305329
version: "0.2.0+2"
306330
sdks:
307-
dart: ">=3.1.0-185.0.dev <4.0.0"
331+
dart: ">=3.2.0-0 <4.0.0"
308332
flutter: ">=3.0.0"

packages/desktop_webview_window/example/windows/flutter/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
99
# https://github.com/flutter/flutter/issues/57146.
1010
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
1111

12+
# Set fallback configurations for older versions of the flutter tool.
13+
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
14+
set(FLUTTER_TARGET_PLATFORM "windows-x64")
15+
endif()
16+
1217
# === Flutter Library ===
1318
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
1419

@@ -91,7 +96,7 @@ add_custom_command(
9196
COMMAND ${CMAKE_COMMAND} -E env
9297
${FLUTTER_TOOL_ENVIRONMENT}
9398
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
94-
windows-x64 $<CONFIG>
99+
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
95100
VERBATIM
96101
)
97102
add_custom_target(flutter_assemble DEPENDS
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
class WebviewCookie {
2+
final String name;
3+
final String value;
4+
final String domain;
5+
final String path;
6+
final DateTime? expires;
7+
final bool secure;
8+
final bool httpOnly;
9+
final bool sessionOnly;
10+
11+
WebviewCookie({
12+
required this.name,
13+
required this.value,
14+
required this.domain,
15+
required this.path,
16+
required this.expires,
17+
required this.secure,
18+
required this.httpOnly,
19+
required this.sessionOnly,
20+
});
21+
22+
factory WebviewCookie.fromJson(Map<String, dynamic> json) {
23+
return WebviewCookie(
24+
name: json['name'],
25+
value: json['value'],
26+
domain: json['domain'],
27+
expires: json['expires'] == null
28+
? null
29+
: DateTime.fromMillisecondsSinceEpoch(
30+
((json['expires'] as num) * 1000).toInt(),
31+
),
32+
httpOnly: json['httpOnly'] ?? false,
33+
path: json['path'],
34+
secure: json['secure'] ?? false,
35+
sessionOnly: json['sessionOnly'] ?? false,
36+
);
37+
}
38+
39+
Map<String, dynamic> toJson() {
40+
return {
41+
'name': name,
42+
'value': value,
43+
'domain': domain,
44+
'path': path,
45+
'expires':
46+
expires == null ? null : expires!.millisecondsSinceEpoch ~/ 1000,
47+
'secure': secure,
48+
'httpOnly': httpOnly,
49+
'sessionOnly': sessionOnly,
50+
};
51+
}
52+
}

0 commit comments

Comments
 (0)