-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathiframe_check.ex
More file actions
48 lines (40 loc) · 1.14 KB
/
iframe_check.ex
File metadata and controls
48 lines (40 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
defmodule LiveDebuggerWeb.Hooks.IframeCheck do
@moduledoc """
This hook is used to check if the current page is inside an iframe.
It assigns the `:in_iframe?` assign based on the connect params.
Mock is created for it to simulate LiveDebugger in iframe in e2e tests.
"""
@callback on_mount(
:add_hook,
params :: map(),
session :: map(),
socket :: Phoenix.LiveView.Socket.t()
) ::
{:cont, Phoenix.LiveView.Socket.t()}
def on_mount(:add_hook, params, session, socket) do
impl().on_mount(:add_hook, params, session, socket)
end
defp impl() do
Application.get_env(
:live_debugger,
:iframe_check,
__MODULE__.Impl
)
end
defmodule Impl do
@moduledoc false
import Phoenix.LiveView
import Phoenix.Component
def on_mount(:add_hook, _params, _session, socket) do
in_iframe? =
if connected?(socket) do
socket
|> get_connect_params()
|> Map.get("in_iframe?", false)
else
false
end
{:cont, assign(socket, :in_iframe?, in_iframe?)}
end
end
end