mirror of
https://github.com/penpot/penpot.git
synced 2025-02-02 04:19:08 -05:00
✨ Detect if rasterizer iframe is blocked
This commit is contained in:
parent
16c8c4bd2a
commit
99e323dabc
1 changed files with 26 additions and 3 deletions
|
@ -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))))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue