Skip to content

Commit ab0990a

Browse files
FluorescentHallucinogentoji
authored andcommitted
Fix crashes and console errors
1 parent b7f97a2 commit ab0990a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

tests/permission-request.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
const title = 'Notification title';
7777

7878
const options = {
79-
body: `This notification can have a maximum of ${Notification.maxActions || 0} action button(s). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`,
79+
body: `This notification can have a maximum of ${window.Notification?.maxActions || 0} action button(s). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`,
8080
data: {
8181
url: 'https://google.com',
8282
},
@@ -119,7 +119,7 @@
119119
],
120120
};
121121

122-
const showNotification = () => serviceWorkerRegistration.showNotification(title, options);
122+
const showNotification = () => serviceWorkerRegistration?.showNotification?.(title, options);
123123

124124
let deferredPrompt;
125125

@@ -130,8 +130,8 @@
130130
});
131131

132132
const installPWA = async (success, _) => {
133-
deferredPrompt.prompt();
134-
const { outcome } = await deferredPrompt.userChoice;
133+
deferredPrompt?.prompt();
134+
const { outcome } = await deferredPrompt?.userChoice;
135135
if (outcome === 'accepted') {
136136
success();
137137
}
@@ -189,34 +189,34 @@
189189
{
190190
icon: '../media/textures/microphone-button.png',
191191
callback: (success, fail) => {
192-
navigator.mediaDevices.getUserMedia({ audio: true })
192+
navigator.mediaDevices?.getUserMedia?.({ audio: true })
193193
.then(success, fail);
194194
}
195195
},
196196
{
197197
icon: '../media/textures/camera-button.png',
198198
callback: (success, fail) => {
199-
navigator.mediaDevices.getUserMedia({ video: true })
199+
navigator.mediaDevices?.getUserMedia?.({ video: true })
200200
.then(success, fail);
201201
}
202202
},
203203
{
204204
icon: '../media/textures/screenshare-button.png',
205205
callback: (success, fail) => {
206-
navigator.mediaDevices.getDisplayMedia()
206+
navigator.mediaDevices?.getDisplayMedia?.()
207207
.then(success, fail);
208208
}
209209
},
210210
{
211211
icon: '../media/textures/location-button.png',
212212
callback: (success, fail) => {
213-
navigator.geolocation.getCurrentPosition(success, fail);
213+
navigator.geolocation?.getCurrentPosition?.(success, fail);
214214
}
215215
},
216216
{
217217
icon: '../media/textures/notifications-button.png',
218218
callback: (success, fail) => {
219-
Notification.requestPermission(outcome => {
219+
window.Notification?.requestPermission?.(outcome => {
220220
switch(outcome) {
221221
case 'granted':
222222
success();
@@ -237,7 +237,7 @@
237237
{
238238
icon: '../media/textures/bluetooth-button.png',
239239
callback: (success, fail) => {
240-
navigator.bluetooth.requestDevice({
240+
navigator.bluetooth?.requestDevice?.({
241241
// filters: [...] <- Prefer filters to save energy & show relevant devices.
242242
// acceptAllDevices here ensures dialog can populate, we don't care with what.
243243
acceptAllDevices: true
@@ -249,28 +249,28 @@
249249
{
250250
icon: '../media/textures/usb-button.png',
251251
callback: (success, fail) => {
252-
navigator.usb.requestDevice({ filters: [{}] })
252+
navigator.usb?.requestDevice?.({ filters: [{}] })
253253
.then(success, fail);
254254
}
255255
},
256256
{
257257
icon: '../media/textures/hid-button.png',
258258
callback: (success, fail) => {
259-
navigator.hid.requestDevice({ filters: [] })
259+
navigator.hid?.requestDevice?.({ filters: [] })
260260
.then(devices => { devices.length > 0 ? success() : fail() });
261261
}
262262
},
263263
{
264264
icon: '../media/textures/midi-button.png',
265265
callback: (success, fail) => {
266-
navigator.requestMIDIAccess({ sysex: true })
266+
navigator.requestMIDIAccess?.({ sysex: true })
267267
.then(success, fail);
268268
}
269269
},
270270
{
271271
icon: '../media/textures/serial-button.png',
272272
callback: (success, fail) => {
273-
navigator.serial.requestPort({ filters: [] })
273+
navigator.serial?.requestPort?.({ filters: [] })
274274
.then(success, fail);
275275
}
276276
},

0 commit comments

Comments
 (0)