Skip to content

Commit 4e840ae

Browse files
authored
fix: don't crash on safari<16 (#1383)
* fix: don't crash on safari<16 * fix: apply PR Pre-launch Checklist
1 parent 416e7b0 commit 4e840ae

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

permission_handler_html/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.3+3
2+
3+
- Safari < 16 compatibility: Don't crash on missing `window.navigator.permissions` property
4+
15
## 0.1.3+2
26

37
- `web: 1.0.0` compatibility: `PermissionDescriptor` was removed in web package.

permission_handler_html/lib/permission_handler_html.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:js_interop_unsafe';
23

34
import 'package:web/web.dart' as web;
45

@@ -12,8 +13,15 @@ import 'web_delegate.dart';
1213
class WebPermissionHandler extends PermissionHandlerPlatform {
1314
static final web.MediaDevices _devices = web.window.navigator.mediaDevices;
1415
static final web.Geolocation _geolocation = web.window.navigator.geolocation;
15-
static final web.Permissions _htmlPermissions =
16-
web.window.navigator.permissions;
16+
static final web.Permissions? _htmlPermissions = (() {
17+
// Using unsafe interop to check availability of `permissions`.
18+
// It's not defined as nullable, so merely loading it into a web.Permission? variable
19+
// causes the null-check to fail
20+
if (!web.window.navigator.has("permissions")) {
21+
return null;
22+
}
23+
return web.window.navigator.permissions;
24+
})();
1725

1826
final WebDelegate _webDelegate;
1927

permission_handler_html/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: permission_handler_html
22
description: Permission plugin for Flutter. This plugin provides the web API to request and check permissions.
3-
version: 0.1.3+2
3+
version: 0.1.3+3
44

55
homepage: https://github.com/baseflow/flutter-permission-handler
66

0 commit comments

Comments
 (0)