Socket
Socket
Sign inDemoInstall

@mapbox/mapbox-gl-supported

Package Overview
Dependencies
Maintainers
14
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/mapbox-gl-supported - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc