Embedded JavaScript Events Not running. I need your help.

Excuse me

I wrote the following code

first step

/demo.php

code:

<script>
window.addEventListener("message", function(event) {
 console.log(JSON.parse(event.data));
});
</script>

<iframe
  id="looker"
  src="https://instance_name.looker.com/embed/dashboards/1?embed_domain=http://localhost:8010">
</iframe>

Second step
Looker control : Admin -> Embed -> Whitelisting the Embed Domain :
http://localhost:8010 add it, update.

third step
http://localhost:8010/demo.php running,

Look can be displayed normally in the web page.

But EventListener does not work properly, and no message is received.

what am I doing wrong? Please tell me, thank you very much.

0 4 1,469
4 REPLIES 4

This stuff is always really hard to troubleshoot! I remember spending so long doing this when I first learned.

Your code looks fine to me.
Here’s an example of a demo (the finished HTML) that’s working fine for me right now. I’ve obfuscated some of my sso embed URL URL but the structure is all the same. It looks pretty much identical to yours, from what I can see.

<script>
    window.addEventListener("message", function (event) {
            if (event.source === document.getElementById("looker").contentWindow) { // confirm message came from iFrame with id Looker
                    console.log(JSON.parse(event.data));
            }
    });

    
</script>

<div class="container" id="header">
	<center><h1>Embed Demo</h1></center>
</div>
<div id="data">
    <iframe id="looker" width=500 height=500 src=https://xxxxx.dev.looker.com/login/embed/%2Fembed%2Fdashboards%2F99%3Fembed_domain%3Dhttp%3A%2F%2F127.0.0.1%3A5000?nonce=%%22&amp;time=1585963535&amp;session_length=900&amp;external_user_id=57&amp;-------------&amp;force_logout_login=true> </iframe>
</div>

I’m not sure what could be going wrong on your side besides embed_domain issues, but maybe my example will help! I would double and triple check your embed domain.

Hi izzy

Your code helped me a lot, and I am also the sso embed URL. According to your method, it has been successful.

Thank you very much ~

How did you solve it? I tried same steps but not able to solve the problem.
Can you please guide me. @caomenglong

hi Ankit_Vishnoi:

You can use the developer tools of IE or Chrome.

Use the network monitoring function inside to see if there is an embed_domain parameter in the jump page after SSO login. The reason why I failed is that it is wrong to generate SSOURL. After the SSO login is successful, the embed_domain parameter is missing in the URL of the jumped look page.

like this

SSO:
https://xxxxx.looker.com/login/embed/embed/looks/100?embed_domain=https://localhost&show_title=false...""&user_attributes={}&access_filters={}&first_name="\u592a\u90ce1"&last_name="\u5c71\u75301"&force_logout_login=false&signature=QbgRX6rbXMRH0aT+dwy0hDfXEpo=

SSO After Jumped Url:

https://xxxxx.looker.com/embed/looks/157?embed_domain=https://localhost&show_title=false&param1=1&pa...