@mapbox/mapbox-gl-supported
Advanced tools
Comparing version 1.4.1 to 1.5.0
59
index.js
@@ -8,2 +8,3 @@ 'use strict'; | ||
window.mapboxgl.supported = isSupported; | ||
window.mapboxgl.notSupportedReason = notSupportedReason; | ||
} | ||
@@ -20,15 +21,18 @@ | ||
function isSupported(options) { | ||
return !!( | ||
isBrowser() && | ||
isArraySupported() && | ||
isFunctionSupported() && | ||
isObjectSupported() && | ||
isJSONSupported() && | ||
isWorkerSupported() && | ||
isUint8ClampedArraySupported() && | ||
isArrayBufferSupported() && | ||
isWebGLSupportedCached(options && options.failIfMajorPerformanceCaveat) | ||
); | ||
return !notSupportedReason(options); | ||
} | ||
function notSupportedReason(options) { | ||
if (!isBrowser()) return 'not a browser'; | ||
if (!isArraySupported()) return 'insufficent Array support'; | ||
if (!isFunctionSupported()) return 'insufficient Function support'; | ||
if (!isObjectSupported()) return 'insufficient Object support'; | ||
if (!isJSONSupported()) return 'insufficient JSON support'; | ||
if (!isWorkerSupported()) return 'insufficient worker support'; | ||
if (!isUint8ClampedArraySupported()) return 'insufficient Uint8ClampedArray support'; | ||
if (!isArrayBufferSupported()) return 'insufficient ArrayBuffer support'; | ||
if (!isCanvasGetImageDataSupported()) return 'insufficient Canvas/getImageData support'; | ||
if (!isWebGLSupportedCached(options && options.failIfMajorPerformanceCaveat)) return 'insufficient WebGL support'; | ||
} | ||
function isBrowser() { | ||
@@ -116,2 +120,15 @@ return typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
// Some browsers or browser extensions block access to canvas data to prevent fingerprinting. | ||
// Mapbox GL uses this API to load sprites and images in general. | ||
function isCanvasGetImageDataSupported() { | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = canvas.height = 1; | ||
const context = canvas.getContext('2d'); | ||
if (!context) { | ||
return false; | ||
} | ||
const imageData = context.getImageData(0, 0, 1, 1); | ||
return imageData && imageData.width === canvas.width; | ||
} | ||
var isWebGLSupportedCache = {}; | ||
@@ -134,4 +151,3 @@ function isWebGLSupportedCached(failIfMajorPerformanceCaveat) { | ||
function isWebGLSupported(failIfMajorPerformanceCaveat) { | ||
function getWebGLContext(failIfMajorPerformanceCaveat) { | ||
var canvas = document.createElement('canvas'); | ||
@@ -161,1 +177,18 @@ | ||
} | ||
function isWebGLSupported(failIfMajorPerformanceCaveat) { | ||
const gl = getWebGLContext(failIfMajorPerformanceCaveat); | ||
if (!gl) { | ||
return false; | ||
} | ||
// Try compiling a shader and get its compile status. Some browsers like Brave block this API | ||
// to prevent fingerprinting. Unfortunately, this also means that Mapbox GL won't work. | ||
const shader = gl.createShader(gl.VERTEX_SHADER); | ||
if (!shader || gl.isContextLost()) { | ||
return false; | ||
} | ||
gl.shaderSource(shader, 'void main() {}'); | ||
gl.compileShader(shader); | ||
return gl.getShaderParameter(shader, gl.COMPILE_STATUS) === true; | ||
} |
{ | ||
"name": "@mapbox/mapbox-gl-supported", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "A library to determine if a browser supports Mapbox GL JS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
16992
162
8