ref: 255744676c0c4c8fa391d7a03bdd3142d6db0ad2
parent: b66a38bbdc4405cce7050b8e8bbcae8d69c3dc2c
author: Ben Harris <[email protected]>
date: Wed Mar 22 18:54:08 EDT 2023
KaiOS: be more careful detecting the presence of KaiAds Now that we catch JavaScript errors and report them to the user, I could tell that the way we were detecting the presence of getKaiAd() didn't work because it caused an alert every time a build without KaiAds was started. Detecting the presence of a global variable is slightly tricky, but explicitly looking for it on "window" works and isn't very ugly.
--- a/kaios/kaiads-glue.js
+++ b/kaios/kaiads-glue.js
@@ -11,7 +11,7 @@
(function() {
// To run, we need to be on KaiOS with the KaiAds SDK and the
// Open Web Apps API.
- if (getKaiAd === undefined || navigator.mozApps === undefined ||
+ if (window.getKaiAd === undefined || navigator.mozApps === undefined ||
navigator.userAgent.toLowerCase().indexOf('kaios') == -1) return;
// If those prerequisites are satisfied, install the button.
var advertbutton = document.createElement("button");