Skip to content

Commit

Permalink
Fix: Prevent webGL error when prefetching Preview.js (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Apr 18, 2017
1 parent f7bea68 commit e0a420a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/lib/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ class Browser {
static hasWebGL() {
if (!gl) {
const canvas = document.createElement('canvas');
// Should stop 'Rats! WebGL hit a snag' error when checking WebGL support
canvas.addEventListener('webglcontextlost', (e) => {
e.preventDefault();
e.stopPropagation();
});


try {
gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
Expand Down
41 changes: 24 additions & 17 deletions src/lib/Logger.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import Browser from './Browser';

const BROWSER_INFO = {
name: Browser.getName(),
swf: Browser.hasFlash(),
svg: Browser.hasSVG(),
mse: Browser.hasMSE(),
webgl: Browser.hasWebGL(),
mp3: Browser.canPlayMP3(),
dash: Browser.canPlayDash(),
box3d: Browser.supportsModel3D(),
h264: {
baseline: Browser.canPlayH264Baseline(),
main: Browser.canPlayH264Main(),
high: Browser.canPlayH264High()
}
};

/* eslint-disable no-undef */
const CLIENT_NAME = __NAME__;
const CLIENT_VERSION = __VERSION__;
Expand All @@ -34,7 +18,7 @@ class Logger {
this.log = {
locale,
event: 'preview',
browser: BROWSER_INFO,
browser: this.getBrowserInfo(),
client: {
name: CLIENT_NAME,
version: CLIENT_VERSION
Expand All @@ -52,6 +36,29 @@ class Logger {
};
}

/**
* Gets browser capability information.
*
* @return {Object} Browser capability information
*/
getBrowserInfo() {
return {
name: Browser.getName(),
swf: Browser.hasFlash(),
svg: Browser.hasSVG(),
mse: Browser.hasMSE(),
webgl: Browser.hasWebGL(),
mp3: Browser.canPlayMP3(),
dash: Browser.canPlayDash(),
box3d: Browser.supportsModel3D(),
h264: {
baseline: Browser.canPlayH264Baseline(),
main: Browser.canPlayH264Main(),
high: Browser.canPlayH264High()
}
};
}

/**
* Marks file as cached.
*
Expand Down

0 comments on commit e0a420a

Please sign in to comment.