ac8cb5e1 by David LaPalomento

Avoid Firefox issue 548397

getComputedStyle returns null when in an iframe with display: none so be careful dereferencing it.
1 parent 1c31597b
...@@ -17,6 +17,7 @@ var ...@@ -17,6 +17,7 @@ var
17 // The amount of time to wait between checking the state of the buffer 17 // The amount of time to wait between checking the state of the buffer
18 bufferCheckInterval = 500, 18 bufferCheckInterval = 500,
19 19
20 safeGetComputedStyle,
20 keyFailed, 21 keyFailed,
21 resolveUrl; 22 resolveUrl;
22 23
...@@ -683,6 +684,27 @@ videojs.HlsHandler.prototype.cancelSegmentXhr = function() { ...@@ -683,6 +684,27 @@ videojs.HlsHandler.prototype.cancelSegmentXhr = function() {
683 }; 684 };
684 685
685 /** 686 /**
687 * Returns the CSS value for the specified property on an element
688 * using `getComputedStyle`. Firefox has a long-standing issue where
689 * getComputedStyle() may return null when running in an iframe with
690 * `display: none`.
691 * @see https://bugzilla.mozilla.org/show_bug.cgi?id=548397
692 */
693 safeGetComputedStyle = function(el, property) {
694 var result;
695 if (!el) {
696 return '';
697 }
698
699 result = getComputedStyle(el);
700 if (!result) {
701 return '';
702 }
703
704 return result[property];
705 };
706
707 /**
686 * Abort all outstanding work and cleanup. 708 * Abort all outstanding work and cleanup.
687 */ 709 */
688 videojs.HlsHandler.prototype.dispose = function() { 710 videojs.HlsHandler.prototype.dispose = function() {
...@@ -760,8 +782,8 @@ videojs.HlsHandler.prototype.selectPlaylist = function () { ...@@ -760,8 +782,8 @@ videojs.HlsHandler.prototype.selectPlaylist = function () {
760 // (this could be the lowest bitrate rendition as we go through all of them above) 782 // (this could be the lowest bitrate rendition as we go through all of them above)
761 variant = null; 783 variant = null;
762 784
763 width = parseInt(getComputedStyle(this.tech_.el()).width, 10); 785 width = parseInt(safeGetComputedStyle(this.tech_.el(), 'width'), 10);
764 height = parseInt(getComputedStyle(this.tech_.el()).height, 10); 786 height = parseInt(safeGetComputedStyle(this.tech_.el(), 'height'), 10);
765 787
766 // iterate through the bandwidth-filtered playlists and find 788 // iterate through the bandwidth-filtered playlists and find
767 // best rendition by player dimension 789 // best rendition by player dimension
......
...@@ -3106,6 +3106,26 @@ test('does not process update end until buffered value has been set', function() ...@@ -3106,6 +3106,26 @@ test('does not process update end until buffered value has been set', function()
3106 ok(!player.tech_.hls.pendingSegment_, 'pending segment cleared out'); 3106 ok(!player.tech_.hls.pendingSegment_, 'pending segment cleared out');
3107 }); 3107 });
3108 3108
3109 // workaround https://bugzilla.mozilla.org/show_bug.cgi?id=548397
3110 test('selectPlaylist does not fail if getComputedStyle returns null', function() {
3111 var oldGetComputedStyle = window.getComputedStyle;
3112 window.getComputedStyle = function() {
3113 return null;
3114 };
3115
3116 player.src({
3117 src: 'master.m3u8',
3118 type: 'application/vnd.apple.mpegurl'
3119 });
3120 openMediaSource(player);
3121 standardXHRResponse(requests.shift()); // master
3122 standardXHRResponse(requests.shift()); // media
3123
3124 player.tech_.hls.selectPlaylist();
3125 ok(true, 'should not throw');
3126 window.getComputedStyle = oldGetComputedStyle;
3127 });
3128
3109 module('Buffer Inspection'); 3129 module('Buffer Inspection');
3110 3130
3111 test('detects time range end-point changed by updates', function() { 3131 test('detects time range end-point changed by updates', function() {
......