DEV: Abort placing adsense if Ember component is destroyed (#190)
This should avoid surprising error messages being printed to the console
This commit is contained in:
parent
789be84744
commit
36f4ebc64b
|
@ -141,22 +141,27 @@ export default AdComponent.extend({
|
||||||
this._super();
|
this._super();
|
||||||
},
|
},
|
||||||
|
|
||||||
_triggerAds() {
|
async _triggerAds() {
|
||||||
if (isTesting()) {
|
if (isTesting()) {
|
||||||
return; // Don't load external JS during tests
|
return; // Don't load external JS during tests
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set("adRequested", true);
|
this.set("adRequested", true);
|
||||||
loadAdsense().then(function () {
|
|
||||||
const adsbygoogle = window.adsbygoogle || [];
|
await loadAdsense();
|
||||||
|
|
||||||
|
if (this.isDestroyed || this.isDestroying) {
|
||||||
|
// Component removed from DOM before script loaded
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const adsbygoogle = (window.adsbygoogle ||= []);
|
||||||
adsbygoogle.push({}); // ask AdSense to fill one ad unit
|
adsbygoogle.push({}); // ask AdSense to fill one ad unit
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error("Adsense error:", ex);
|
console.error("Adsense error:", ex);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
|
|
Loading…
Reference in New Issue