import type { WordPressWindow, ShopifyWindow } from "~/types/window"; import { Platform } from "~/types/bot"; import { withErrorHandling } from "./sentry"; export const detectPlatform = withErrorHandling("detectPlatform", (): Platform => { if (typeof window === "undefined" || typeof document === "undefined") { return Platform.OTHER; } const wpWindow = window as WordPressWindow; const shopifyWindow = window as ShopifyWindow; if ( typeof wpWindow.wp !== "undefined" || typeof wpWindow.wc !== "undefined" || document.querySelector('meta[name="generator"][content*="WordPress"]') ) { return Platform.WORDPRESS_WOOCOMMERCE; } if ( typeof shopifyWindow.Shopify !== "undefined" || document.querySelector('meta[name="shopify-checkout-api-token"]') || document.querySelector('script[src*="cdn.shopify.com"]') ) { return Platform.SHOPIFY; } return Platform.OTHER; });