Skip to content

Repository files navigation

@playcode/embed

Embed a live Playcode Cloud project - an AI-built, full-stack website or app - into any web page. Zero dependencies, framework-agnostic, responsive, and lazy-loaded.

Playcode is an AI app builder for non-technical teams: describe the software you want in plain English, Playcode AI builds it, and Playcode Cloud runs it with a real backend, database, HTTPS, and custom domains. Every Cloud project is served at https://{slug}.playcode.ai, so this package wraps it in a clean, responsive iframe for your portfolio, docs, blog, or landing page.

npm install @playcode/embed

Cloud and browser projects are both embeddable. Cloud projects (https://{slug}.playcode.ai) are the default. Browser projects (https://{slug}.playcode.io) also work - pass host: "playcode.io". See Embeddability for the one caveat (an app that sets its own X-Frame-Options / CSP frame-ancestors).

Quick start

Web component (recommended)

<scripttype="module">import{definePlaycodeEmbed}from'@playcode/embed/web-component'definePlaycodeEmbed()</script><playcode-embedproject="ianberdin" aspect-ratio="16/9"></playcode-embed>

From a CDN, no build step

<scriptsrc="https://unpkg.com/@playcode/embed"></script><!-- Auto-embedded on load: --><divdata-playcode="ianberdin" data-aspect-ratio="16/9"></div>

Programmatic API

import{playcodeEmbed}from'@playcode/embed'playcodeEmbed('#preview',{project: 'ianberdin',// slug, numeric id, or uid from the Cloud project URLaspectRatio: '16/9',lazy: true,attribution: true,})

Build a URL only (SSR / frameworks)

import{buildEmbedUrl}from'@playcode/embed'buildEmbedUrl({project: 'ianberdin'})// "https://ianberdin.playcode.ai"buildEmbedUrl({project: 'ianberdin',port: 5432})// "https://5432--ianberdin.playcode.ai" (non-default Cloud port)buildEmbedUrl({url: 'https://app.acme.com',params: {theme: 'dark'}})// "https://app.acme.com/?theme=dark" (custom domain)

Embeddability

Project typeURLEmbeddable cross-origin?
Cloud (full-stack app)https://{slug}.playcode.aiYes (default)
Browser (client-only)https://{slug}.playcode.ioYes - pass host: "playcode.io"
Custom domainyour domainDepends on the app's own headers

If your own app sets X-Frame-Options or a CSP frame-ancestors directive, those win - the embed will be blocked regardless of this library.

Options

OptionTypeDefaultDescription
projectstring-Project slug, numeric id, or uid (e.g. "my-app" or "1374").
urlstring-Full URL to embed (custom domains, hand-built preview URLs). Overrides project.
hoststring"playcode.ai"Host serving the project. Cloud (playcode.ai) is frameable; browser (playcode.io) is not.
portnumber-Expose a non-default Cloud port ({port}--{slug}.{host}).
aspectRatiostring"16/10"Responsive CSS aspect ratio, e.g. "16/9".
heightstring-Fixed CSS height. Overrides aspectRatio.
lazybooleantrueLoad the iframe when it scrolls into view.
attributionbooleantrueShow a "Built with Playcode" link below the frame.
titlestring"Playcode project"Accessible iframe title.
paramsRecord<string,string>-Extra query params appended to the embed URL.
allowstringsensible defaultiframe permissions-policy allow attribute.
sandboxstring | nullsensible defaultiframe sandbox; pass null to omit.

Web-component attributes are the kebab-case equivalents (aspect-ratio, data-playcode, ...).

Exports

  • @playcode/embed - buildEmbedUrl, playcodeEmbed, autoEmbed.
  • @playcode/embed/web-component - definePlaycodeEmbed, PlaycodeEmbedElement.
  • @playcode/embed/auto - everything, plus auto-registration on load (the CDN build).

Ships ESM, CommonJS, TypeScript types, and a minified IIFE for <script> tags.

Links

License

MIT (c) Playcode

About

Embed a live Playcode project (AI-built, Cloud-hosted website or app) into any web page. Zero dependencies, framework-agnostic.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages