// blog
Embed a Web Tool in Other Websites, Safely
Allow framing on one page only, with frame-ancestors set per path and X-Frame-Options left out there. Let the host page read the file itself and hand it to the frame with postMessage, which avoids CORS and works with logged-in downloads. Check message sources on both sides, transfer the bytes, expect storage to be blocked in a third-party frame, and treat the embedding site’s name as a hint, not proof.

Our free board viewer can be embedded in other websites with two lines of HTML. This post is for developers: the decisions that let other sites show it without opening holes in ours. They apply to any tool you want to let others embed.
One page may be framed, every other refuses
Every page on aiwebcenter.com sends frame-ancestors 'none' and X-Frame-Options: DENY, so no site can show it in a frame. That stops clickjacking, and it stays.
The embedded viewer is its own page, /tools/board-viewer/embed/, and only that path gets frame-ancestors *. In nginx that’s a map on the path, used in the shared headers:
map $uri $aiw_ancestors {
~^/tools/board-viewer/embed/ "*";
default "'none'";
}
map $uri $aiw_xfo {
~^/tools/board-viewer/embed/ "";
default "DENY";
}
An empty value makes nginx leave the header out, so the embed page has no X-Frame-Options at all. The page has no sign-in, nothing to click on anyone’s behalf, and none of the site’s other features.
One core, two homes
The embed page isn’t a copy of the viewer. It’s the same React component with an embed property: a strip with our name and links on top, no site header or footer, and the options a host can set. Every fix to the viewer reaches both at once.
The host page reads the file, then hands it over
The obvious design is a link: the frame fetches the file from the forum. That needs CORS on the forum’s server, which most can’t add, and it fails for attachments behind a login, because a cross-site request doesn’t carry the forum’s cookies.
So the host page does the reading. Our small script on the forum page fetches the file as the signed-in member, same-origin, and passes the bytes into the frame:
frame.contentWindow.postMessage({ type: "aiwc-board:open", files }, ORIGIN, files.map((f) => f.data));
The last argument transfers the ArrayBuffers instead of copying them, which matters for a 50 MB board.
Check who’s talking, both ways
postMessage is only as safe as its checks:
- The frame listens only to
window.parent, and only for the two message types it knows. It never sends anything back butaiwc-board:ready. - The host script only answers a ready signal whose
event.originis exactlyhttps://aiwebcenter.comand whoseevent.sourceis a frame it created itself. It sends the files to that origin by name, never to*. - The options the host sets travel in the frame’s address and are read by one function that accepts only known values. A color is only
#rgbor#rrggbb, so nothing else can reach the page’s styles.
Expect blocked storage
Some browsers block storage in a third-party frame, and some partition it per site. The viewer keeps its view settings in localStorage, and on our own page every read was already wrapped in try. A few writes weren’t. Inside a frame, one of those would have thrown and broken the viewer. Now every write goes through one helper that does nothing when storage is off.
Which site am I in? A hint, not proof
The viewer needs the embedding site’s name for Ask AI’s per-site limits. It reads location.ancestorOrigins where the browser has it, and falls back to document.referrer. Both come from the visitor’s browser, so a determined person could claim to be another site. We treat the name as a hint and keep every site inside a monthly cap of its own, so a lie can cost no more than that cap. The business side of that is in Let other websites use your AI.
The host’s own security rules
A forum with a strict Content-Security-Policy has to allow our script and frame: script-src and frame-src with https://aiwebcenter.com. The guide for websites lists that under troubleshooting, because it’s the first thing that fails on a well-run site.
How it was tested
Two local servers on different ports, one as the forum and one as aiwebcenter.com, so the browser treats them as different sites. Headless Chrome then checked that the board opened from the forum’s own file without a CORS header, that the options applied, that Ask AI stayed hidden where it was off, and that the strip rolled. The same setup checked a site’s own AI: a stand-in relay streamed an answer back, and our value check flagged a number the board data didn’t have.
The whole build, with the AI side, is in the case study.
Frequently asked questions
Why not just use CORS?
With CORS the file's server has to send a header allowing our site, which most forums can't or won't add, and files behind a login still fail because cross-site requests don't carry the forum's cookies. When the host page reads its own file, neither problem exists.
Is postMessage safe for this?
Yes, with checks on both sides: the frame only listens to the page directly around it, and the host script only answers the frame it created, from our exact origin. The frame never sends anything back but a ready signal.
Does the viewer upload the file?
No. The host page reads it and passes it into the frame in the visitor's browser. It's only sent to us if a board won't open and the visitor chooses to send it.
































































































































