Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 2989bda

Browse files
committed
Test API availability via property access.
1 parent 48e60c1 commit 2989bda

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

js/load-image-fetch.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
})(function (loadImage) {
2626
'use strict'
2727

28-
if (typeof fetch !== 'undefined' && typeof Request !== 'undefined') {
28+
var global = loadImage.global
29+
30+
if (global.fetch && global.Request) {
2931
loadImage.fetchBlob = function (url, callback, options) {
3032
fetch(new Request(url, options))
3133
.then(function (response) {
@@ -36,11 +38,8 @@
3638
callback(null, err)
3739
})
3840
}
39-
} else if (
40-
// Check for XHR2 support:
41-
typeof XMLHttpRequest !== 'undefined' &&
42-
typeof ProgressEvent !== 'undefined'
43-
) {
41+
} else if (global.XMLHttpRequest && global.ProgressEvent) {
42+
// Browser supports XHR Level 2 and XHR responseType blob
4443
loadImage.fetchBlob = function (url, callback, options) {
4544
// eslint-disable-next-line no-param-reassign
4645
options = options || {}

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,8 +2518,8 @@
25182518

25192519
describe('Fetch', function () {
25202520
if (
2521-
!('fetch' in window && 'Request' in window) &&
2522-
!('XMLHttpRequest' in window && 'ProgressEvent' in window)
2521+
!(window.fetch && window.Request) &&
2522+
!(window.XMLHttpRequest && window.ProgressEvent)
25232523
) {
25242524
return
25252525
}

0 commit comments

Comments
 (0)