# Embedding PlayCanvas into a webpage without iframe

**URL:** <https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246>\
**Category:** Help & Support\
**Created:** [January 28, 2021, 4:14pm UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246 "2021-01-28T16:14:08Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [January 28, 2021, 7:49pm UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246/21 "2021-01-28T19:49:10Z")

</div>

Another idea I had would be to use an iframe but inline the PlayCanvas index HTML as a base64 URL. It be slightly bigger in size but I wouldn’t think it be by much given the content of the HTML file.

And after it is gzipped on transport, the size difference is probably very small. This would save the extra network call.

---

<div class="post-metadata">

**Author:** ![Jake\_Johnson](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/jake_johnson/32/7938_2.png) [@Jake\_Johnson](https://forum.playcanvas.com/u/Jake_Johnson)\
**Post date:** [January 28, 2021, 8:10pm UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246/22 "2021-01-28T20:10:39Z")

</div>

That’s a pretty interesting idea. I think what would work best for our particular use case is attempting to change the engine code to allow everything to be baked directly into the webpage, but if that can’t be done or ends up being impossible to scale I think that idea is certainly worth a shot if the size difference isn’t too bad. I guess we’ll see.

Thanks so much for all the help. Do you work for PlayCanvas? If not they should start compensating you lol

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [January 28, 2021, 8:27pm UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246/23 "2021-01-28T20:27:05Z")

</div>

> [@Jake\_Johnson](#):
>
> That’s a pretty interesting idea. I think what would work best for our particular use case is attempting to change the engine code to allow everything to be baked directly into the webpage, but if that can’t be done or ends up being impossible to scale I think that idea is certainly worth a shot if the size difference isn’t too bad. I guess we’ll see.

I do an example of both for you tomorrow.

> [@Jake\_Johnson](#):
>
> Thanks so much for all the help. Do you work for PlayCanvas? If not they should start compensating you lol

Yep, I’m part of the PlayCanvas support team 😅

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [January 29, 2021, 12:17pm UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246/24 "2021-01-29T12:17:51Z")

</div>

I couldn’t get the base64 iframe version to work. Probably due to it needing external files as well in the HTML.

But here are my changes to make embedding PlayCanvas directly into a canvas/div

Repo: [https://github.com/yaustar/playcanvas-embedding-tests](https://github.com/yaustar/playcanvas-embedding-tests)  
Commit Diff: [https://github.com/yaustar/playcanvas-embedding-tests/commit/9fd24541f1d20766015e0860a64057fb8d401025](https://github.com/yaustar/playcanvas-embedding-tests/commit/9fd24541f1d20766015e0860a64057fb8d401025)

It’s not thoroughly tested so you may need to fix any issues that you encounter as this is not a supported use case.

Good luck @Jake_Johnson

---

<div class="post-metadata">

**Author:** ![Jake\_Johnson](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/jake_johnson/32/7938_2.png) [@Jake\_Johnson](https://forum.playcanvas.com/u/Jake_Johnson)\
**Post date:** [January 29, 2021, 5:53pm UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246/25 "2021-01-29T17:53:05Z")

</div>

This is all working beautifully for me thank you so much.

---

<div class="post-metadata">

**Author:** ![Cheburashka](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/cheburashka/32/21630_2.png) [@Cheburashka](https://forum.playcanvas.com/u/Cheburashka)\
**Post date:** [May 29, 2022, 7:22pm UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246/26 "2022-05-29T19:22:36Z")

</div>

Hey there! Thank you for this workaround!  
I’ve been trying to implement this using a recent build from PC but there are some changes in .js files. Anything in particular I should pay attention to this time around?

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [May 30, 2022, 10:53am UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246/27 "2022-05-30T10:53:46Z")

</div>

It’s pretty much the same code, just parts have moved around a bit. Using the diff I posted above, I was able to adopt using the new ` __start__.js` file.

The only thing that is really different is that you no longer need the engine patch as long as you set the fill mode in the PlayCanvas project to ‘NONE’

I’ve include the ZIP here to help:  
[Starter Kit\_ Model Viewer.zip](https://forum.playcanvas.com/uploads/short-url/ccDayUMjgy5PQBmIZ3szzKVRmDq.zip) (4.3 MB)

---

<div class="post-metadata">

**Author:** ![Cheburashka](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/cheburashka/32/21630_2.png) [@Cheburashka](https://forum.playcanvas.com/u/Cheburashka)\
**Post date:** [May 30, 2022, 11:12am UTC](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246/28 "2022-05-30T11:12:53Z")

</div>

Thank you for the fast reply!  
I actually got it to work yesterday, the way I wanted to, from your original repo!  
The only problems came up from my lack of experience with styling and other front end stuff. Might want to keep separate CSS files for the webpage and playcanvas element instead of having tags all over the place Will try out your updated template too. Thanks again!

[Previous page](https://forum.playcanvas.com/t/embedding-playcanvas-into-a-webpage-without-iframe/17246.md?page=1)
