From 255744676c0c4c8fa391d7a03bdd3142d6db0ad2 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 22 Mar 2023 22:54:08 +0000 Subject: [PATCH] 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. --- kaios/kaiads-glue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kaios/kaiads-glue.js b/kaios/kaiads-glue.js index 62634b2..2f7788b 100644 --- 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");