Skip to content

Example: Prebid as ad server with cross-origin (SafeFrame-style) rendering - #6864

Merged
muuki88 merged 2 commits into
prebid:masterfrom
patmmccann:agent-safeframe-example-5067
Oct 28, 2026
Merged

muuki88 merged 2 commits into
prebid:masterfrom
patmmccann:agent-safeframe-example-5067

Conversation

@patmmccann

@patmmccann patmmccann commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #5067.

Adds an example that extends Running Prebid.js as an ad server to render each winning ad in a cross-origin frame. The creative can't touch the publisher page, which is the isolation a SafeFrame provides, without an ad server or extra hosting.

How it works: each ad frame is a data: URL document containing the creative script Prebid.js already uses for cross-domain rendering (integrationExamples/gpt/x-domain/creative.html), followed by pbRender({ adId, pubUrl }). The script asks the page's Prebid.js for the ad over postMessage with a MessageChannel port, then renders it inside the frame. adRenderSucceeded and adRenderFailed fire as usual.

Tested in headless Chrome with the page's own HTML and JS, assembled the way _includes/code/web-example.html does, using the prebid.js@latest not-for-prod build and a debugging intercept for the bids:

  • Both ad units render (adRenderSucceeded).
  • The creative's top.document access throws, so the page isn't reachable.
  • The same setup in a srcdoc iframe sandboxed without allow-same-origin fails. The creative script's nested render frame gets a different opaque origin ("Blocked a frame with origin "null" from accessing a cross-origin frame"). The page explains why allow-same-origin is kept; on a data: document it keeps the frame's own opaque origin.

Also checked on the Netlify preview: after loading the CMP-gated Prebid.js (v11.43 from the CDN), both ad units render in data: frames and neither creative can reach the page. The docs site only loads Prebid.js after consent, so this example, like the existing one, does nothing until a visitor consents.

The page's notes cover the limits:

  • Opaque-origin creatives can't use cookies or localStorage. The alternative is hosting the creative document on a separate domain, the GAM SafeFrame model.
  • The SafeFrame $sf.ext API (expand, geometry) isn't provided. That's what the proposed Secure Creative Rendering module (Secure Creative Rendering Module Prebid.js#15847) would add.

Other details:

  • The JS writes < as \x3C in its string literals, because the include prints the JS unescaped in the "js" and "source" tabs. A literal <script> there would break the page.
  • Also adds a sidebar entry next to the existing no-ad-server example.
  • markdownlint-cli2 0.20.0 (CI's version) and 0.22.1 pass.

🤖 Generated with Claude Code

…rendering

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for prebid-docs-preview ready!

Name Link
🔨 Latest commit 244ee3b
🔍 Latest deploy log https://app.netlify.com/projects/prebid-docs-preview/deploys/6ae0b066e93a8ae860919c62
😎 Deploy Preview https://deploy-preview-6864--prebid-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T21:12:41.413117Z 9f85c15 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f85c1580b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// A data: URL document has its own opaque origin, so the creative can't reach this page.
// allow-same-origin keeps that opaque origin (it doesn't grant this page's origin); it's needed
// because the creative script renders the ad in a nested frame it has to script.
iframe.sandbox = 'allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-top-navigation-by-user-activation';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow form submission for interactive creatives

When a rich-media winning creative submits an HTML <form>, this sandbox lacks allow-forms, so the browser blocks the submission; the base example this page claims to extend explicitly preserves that capability in dev-docs/examples/no-adserver.md:85-92. Users copying this variant will therefore get an ad that renders but cannot submit, so carry allow-forms into this token list (or document the intentional incompatibility).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This comment was written by an AI agent (Claude Code) on behalf of @patmmccann.

Agreed. Fixed in 244ee3b: allow-forms is added to the iframe's sandbox tokens, matching the base example; nothing else changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@patmmccann
patmmccann requested a review from dgirardi October 27, 2026 14:39
@muuki88
muuki88 merged commit 23422c4 into prebid:master Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should create an example page for Prebid & Safeframes

2 participants