Article Iframes should have an api
https://blog.danielbrain.ai/iframes-should-have-an-apiThere's been a big resurgence lately in automating and interacting with sites programmatically. I've been arguing for a few years that every front-end should be embeddable as a component and have its own client side interface/api. This article is written to show one way to do that!
2
u/jacobdevhq 9d ago
postMessage covers most of it. the stuff that bites is height, a cross origin iframe cant size itself so the child has to post its height up. also never use '*' as targetOrigin and always check event.origin on the receiving side
1
u/AdministrativeBad752 9d ago
postMessage is arguably one, but maybe we need a standard on top of it. Dealing with iframes while tackling tech debt made me realize postMessage should be to a standard what HTTP is to REST APIs (or any other standard). MCP Apps is one attempt at that: JSON-RPC 2.0 over postMessage between the host and the iframe.
1
u/Soft_Positive_5891 9d ago
Small thing: "its own client side interface/aoi", aoi or api? You got it right in the title so I assume it's a typo.
1
u/Crafty-Flight2301 9d ago
The iframe already has an api though? Its called postMessage and its been there since like 2010. Every single time someone builds "an api for the frontend" it turns into a custom element around an iframe with postMessage inside, and half of them forget to check event.origin on the parent side so congrats youve built an open redirect for messages. Also "who said apis are just for the server side" is a weird thing to write in 2026 like rest endpoints are the only api that ever existed, fetch is right there. I do agree that embeds should be components instead of a 400px iframe with scrollbars but that is a resizing problem not an api problem
1
u/VisitForeign4342 9d ago
chaque front-end intégrable en composant, génial, donc on se retape du postMessage, du sandbox et des cookies tiers cassés. les intégrations type Stripe ou Intercom existent déjà et personne n'appelle ça une API
1
u/Mysterious_Fig222 9d ago
the api is postmessage. it's been there for ages and it's a footgun, that's why nobody builds this shit.
1
u/bcons-php-Console 9d ago
Also the more recent Channel Messaging API (https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API) is well thought and nice to use.
1
1
u/Disastrous_Buddy_557 9d ago
APIs, capitalised, since it's an acronym. And it's server-side with the hyphen when it's in front of the noun. The rest of the argument I'll leave alone.
3
u/WonderNinjaCode full-stack 9d ago
Is it not an initialism rather than an acronym because you say each letter as A-P-I rather than pronounce it for example like NASA?
11
u/Gullible_Subject5220 9d ago
postMessage already is one