diff --git a/frontend/src/app/main/rasterizer.cljs b/frontend/src/app/main/rasterizer.cljs index 3fb1f2ca1..bab16ebef 100644 --- a/frontend/src/app/main/rasterizer.cljs +++ b/frontend/src/app/main/rasterizer.cljs @@ -13,9 +13,11 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] + [app.common.logging :as log] [app.common.uuid :as uuid] [app.config :as cf] [app.util.dom :as dom] + [app.util.http :as http] [beicon.core :as rx] [cuerdas.core :as str])) @@ -108,7 +110,28 @@ (let [iframe (dom/create-element "iframe")] (dom/set-attribute! iframe "src" origin) (dom/set-attribute! iframe "hidden" true) - (dom/append-child! js/document.body iframe) (.addEventListener js/window "message" on-message) - (set! instance iframe) - )) + (->> (http/fetch {:method :head + :uri cf/rasterizer-uri + :mode :no-cors}) + (rx/map (fn [response] + (let [allowed? (not (.-redirected response))] + (when-not allowed? + (log/err :hint "rasterizer iframe blocked by adblocker" :origin origin)) + allowed?))) + (rx/catch (fn [cause] + (log/err :hint "rasterizer iframe blocked by adblocker" :origin origin :cause cause) + (rx/of false))) + + (rx/subs (fn [allowed?] + (if allowed? + (do + (dom/append-child! js/document.body iframe) + (set! instance iframe)) + + (let [new-origin (dm/str (assoc cf/public-uri :path "/rasterizer.html"))] + (log/warn :hint "fallback to main domain" :origin new-origin) + (set! origin new-origin) + (dom/set-attribute! iframe "src" new-origin) + (dom/append-child! js/document.body iframe) + (set! instance iframe))))))))