prevent loading radar for iMessages web preview bot

This commit is contained in:
Andrew Petersen
2025-06-01 17:05:18 -04:00
parent 8afef77ea5
commit 2365a4c0f7

View File

@@ -9,12 +9,24 @@ import * as utils from './radar-utils.mjs';
// TEMPORARY fix to disable radar on ios safari
const isIos = /iP(ad|od|hone)/i.test(window.navigator.userAgent);
const isSafari = !!navigator.userAgent.match(/Version\/[\d.]+.*Safari/);
// NOTE: iMessages/Messages preview is provided by an Apple scraper that uses a
// user-agent similar to: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1)
// AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4
// facebookexternalhit/1.1 Facebot Twitterbot/1.0`. There is currently a bug in
// Messages macos/ios where a constantly crashing website seems to cause an
// entire Messages thread to permanently lockup until the individual website
// preview is deleted! Messages ios will judder but allows the message to be
// deleted eventually. Messages macos beachballs forever and prevents the
// successful deletion. See
// https://github.com/netbymatt/ws4kp/issues/74#issuecomment-2921154962 for more
// context.
const isBot = /twitterbot|Facebot/i.test(window.navigator.userAgent);
const safariIos = isIos && isSafari;
const RADAR_HOST = 'mesonet.agron.iastate.edu';
class Radar extends WeatherDisplay {
constructor(navId, elemId) {
super(navId, elemId, 'Local Radar', !safariIos);
super(navId, elemId, 'Local Radar', !safariIos && !isBot);
this.okToDrawCurrentConditions = false;
this.okToDrawCurrentDateTime = false;
@@ -207,7 +219,7 @@ const radarWorker = () => {
};
// register display
// TEMPORARY: except on safari on IOS
if (!safariIos) {
// TEMPORARY: except on safari on IOS and bots
if (!safariIos && !isBot) {
registerDisplay(new Radar(11, 'radar'));
}