Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
Fix ads script loading - store error to reject on subsequent calls
Browse files Browse the repository at this point in the history
The previous code never resolved or rejected after the ads script tag
failed to load once
  • Loading branch information
gushogg-blake authored and JakeChampion committed Feb 4, 2021
1 parent 3d08089 commit e4439bd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/js/ads.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global google */

let sdkScriptLoaded = false;
let sdkScriptError = null;

function createVideoOverlayElement() {
const overlayEl = document.createElement('div');
Expand Down Expand Up @@ -36,13 +37,16 @@ class VideoAds {

if (sdkScriptLoaded || window.google && window.google.ima) {
resolve();
} else if (sdkScriptError) {
reject(sdkScriptError);
} else {
googleSdkScript.addEventListener('load', () => {
sdkScriptLoaded = true;
resolve();
});

googleSdkScript.addEventListener('error', (e) => {
sdkScriptError = e;
reject(e);
});
}
Expand Down

0 comments on commit e4439bd

Please sign in to comment.