# Does someone has a working keycloak js adapter since 11.0.0?

**URL:** https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734
**Category:** Miscellanaeous
**Created:** [September 5, 2020, 10:17am UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734 "2020-09-05T10:17:25Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Jakob](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jakob/32/1242_2.png) [@Jakob](https://forum.keycloak.org/u/Jakob)
#### Post date: [September 5, 2020, 10:17am UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/1 "2020-09-05T10:17:25Z")

</div>

Hello this post is related to: [Javascript adapter promise error after upgrade to keycloak 11](http://forum.keycloak.org/t/javascript-adapter-promise-error-after-upgrade-to-keycloak-11/4200)

My question is if someone has a working keycloak javascript adapter?  
In my opinion it is completly broken. I testet it with 11.0.0 and now 11.0.2.

Testing:

> ```
> <head>
> <script src="keycloak.js"></script>
> <script>
> var keycloak = new Keycloak({
> url: 'http://localhost:8080/auth',
> realm: 'springboot',
> clientId: 'login-app'
> });
> keycloak.init().then(function(authenticated) {
> alert(authenticated ? 'authenticated' : 'not authenticated');
> }).catch(function() {
> alert('failed to initialize');
> });
> </script>
> </head>
> 
> ```

Error:

> ```
> Uncaught (in promise) TypeError: Cannot read property 'appendChild' of null
> at check3pCookiesSupported (keycloak.js:1305)
> at keycloak.js:366
> 
> ```

---

<div class="post-metadata">

### Author: ![simonjcarr](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/simonjcarr/32/1360_2.png) [@simonjcarr](https://forum.keycloak.org/u/simonjcarr)
#### Post date: [September 9, 2020, 5:55pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/2 "2020-09-09T17:55:59Z")

</div>

I get exactly the same error.

---

<div class="post-metadata">

### Author: ![Jakob](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jakob/32/1242_2.png) [@Jakob](https://forum.keycloak.org/u/Jakob)
#### Post date: [September 9, 2020, 10:25pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/3 "2020-09-09T22:25:21Z")

</div>

hopefully they will be a fix soon. I am thinking about to use a older keycloak version in the meantime, not ideal but the other solution is to implement it myself.

---

<div class="post-metadata">

### Author: ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)
#### Post date: [September 10, 2020, 7:03pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/4 "2020-09-10T19:03:46Z")

</div>

Ok, I was able to reproduce the scenario.  
It seems to happen when you try to initialize the KC adapter in script block in the `<head/>` tag.  
At this time, the document is not ready loaded and the part in the Keycloak JS adapter `document.body.appendChild(...)` will fail.

So, wrap your code in a function and execute in in the `<body onload="...">` tag, or, move it to the end of the body of your html page. Then, the body is already available when executing the script and it will work.

I made a Gist with both options: [https://gist.github.com/dasniko/d40cda68560beaf816eb106c06290ca9](https://gist.github.com/dasniko/d40cda68560beaf816eb106c06290ca9)

IMHO it’s not a bug in Keycloak adapter, you just have to use it in the correct manner. Perhaps it’s worth pointing this out in the docs.

---

<div class="post-metadata">

### Author: ![Jakob](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jakob/32/1242_2.png) [@Jakob](https://forum.keycloak.org/u/Jakob)
#### Post date: [September 10, 2020, 7:57pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/5 "2020-09-10T19:57:45Z")

</div>

@dasniko you are my german hero, thank you 😃

As a backend guy without much JS knowledge, I wouldn’t have figured it out. Probably a good idea to meantion this in the documentation because I and probably also the other people, that have this problem, only copy pasted the docs code.

Greetings

---

<div class="post-metadata">

### Author: ![vmuzikar](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/vmuzikar/32/20_2.png) [@vmuzikar](https://forum.keycloak.org/u/vmuzikar)
#### Post date: [September 18, 2020, 10:31am UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/6 "2020-09-18T10:31:50Z")

</div>

Hi! We’ve [prepared a fix](https://github.com/keycloak/keycloak/pull/7430) and we’d be very grateful if you could check it works for you. Thank you!

---

<div class="post-metadata">

### Author: ![dcr31000](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@dcr31000](https://forum.keycloak.org/u/dcr31000)
#### Post date: [October 7, 2020, 3:03pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/7 "2020-10-07T15:03:20Z")

</div>

Keyloak-js 11.0.2 adapter not working with Keycloak 11 and VueJS. I have a 404 error on [https://keycloak/auth/realms/myrealm/protocol/openid-connect/3p-cookies/step1.html](https://keycloak/auth/realms/myrealm/protocol/openid-connect/3p-cookies/step1.html)

I followed the instructions on [https://www.keycloak.org/securing-apps/vue](https://www.keycloak.org/securing-apps/vue) to secure my VueJS app.

I saw lot of developers with the same error on other websites. I tried your fix @vmuzikar but seems to not working…

---

<div class="post-metadata">

### Author: ![vmuzikar](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/vmuzikar/32/20_2.png) [@vmuzikar](https://forum.keycloak.org/u/vmuzikar)
#### Post date: [October 7, 2020, 3:24pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/8 "2020-10-07T15:24:44Z")

</div>

@dcr31000 Hi! It seems like you’re using newer adapter with older Keycloak version. Also, there were some more fixes in this area. Could you please try it with current master branch?

---

<div class="post-metadata">

### Author: ![dcr31000](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@dcr31000](https://forum.keycloak.org/u/dcr31000)
#### Post date: [October 7, 2020, 3:31pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/9 "2020-10-07T15:31:57Z")

</div>

@vmuzikar Hi, thanks for your reply.  
My Keycloak server version is 11.0.2. I tried with keycloak.js on current master branch and have the same issue.

---

<div class="post-metadata">

### Author: ![vmuzikar](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/vmuzikar/32/20_2.png) [@vmuzikar](https://forum.keycloak.org/u/vmuzikar)
#### Post date: [October 8, 2020, 7:06am UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/10 "2020-10-08T07:06:23Z")

</div>

@dcr31000 Could you please create a ticket in our [issue tracker](https://issues.jboss.org/browse/KEYCLOAK). If possible, please specify as detailed steps to reproduce as possible. Thank you!

---

<div class="post-metadata">

### Author: ![mehtadev17](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mehtadev17](https://forum.keycloak.org/u/mehtadev17)
#### Post date: [November 2, 2020, 4:16pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/11 "2020-11-02T16:16:38Z")

</div>

For me the issue was [Content-Security-Policy](http://www.w3.org/TR/CSP/) under Ream Settings -\> Security Defenses. It required listing out all frame-ancestors.

Something like this:  
`frame-src 'self'; frame-ancestors 'self' http://localhost:8000 localhost:* https://*.xyz.com; object-src 'none';`

---

<div class="post-metadata">

### Author: ![Deb111](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@Deb111](https://forum.keycloak.org/u/Deb111)
#### Post date: [December 13, 2021, 3:29pm UTC](https://forum.keycloak.org/t/does-someone-has-a-working-keycloak-js-adapter-since-11-0-0/4734/12 "2021-12-13T15:29:02Z")

</div>

Can you please share screenshot of the changes you did .if any. We are facing the same issue.
