alibaba/page-agent · warning
Unable to access iframe:
Error message
Unable to access iframe:
What it means
While building the DOM tree, the extractor tries to descend into an iframe's contentDocument to index its children; if access throws (cross-origin iframe, or the frame navigated away mid-read) it logs 'Unable to access iframe:' with the underlying exception and skips that subtree. This is the browser's same-origin policy at work, not a bug in the library.
Source
Thrown at packages/page-controller/src/dom/dom_tree/index.js:1682
}
}
// Process children, with special handling for iframes and rich text editors
if (node.tagName) {
const tagName = node.tagName.toLowerCase()
// Handle iframes
if (tagName === 'iframe') {
try {
const iframeDoc = node.contentDocument || node.contentWindow?.document
if (iframeDoc) {
for (const child of iframeDoc.childNodes) {
const domElement = buildDomTree(child, node, false)
if (domElement) nodeData.children.push(domElement)
}
}
} catch (e) {
console.warn('Unable to access iframe:', e)
}
}
// Handle rich text editors and contenteditable elements
else if (
node.isContentEditable ||
node.getAttribute('contenteditable') === 'true' ||
node.id === 'tinymce' ||
node.classList.contains('mce-content-body') ||
(tagName === 'body' && node.getAttribute('data-id')?.startsWith('mce_'))
) {
// Process all child nodes to capture formatted text
for (const child of node.childNodes) {
const domElement = buildDomTree(child, parentIframe, nodeWasHighlighted)
if (domElement) nodeData.children.push(domElement)
}
} else {
// Handle shadow DOM
if (node.shadowRoot) {View on GitHub (pinned to d02db1ee7c)
Solutions
- Accept the skip: cross-origin iframes cannot be automated from the parent page by design
- If you control the iframe, serve it from the same origin (or set document.domain is NOT recommended; prefer same-origin hosting)
- For extension automation, inject the page-controller into the iframe itself (content_scripts all_frames: true) and drive it per-frame
- Re-run updateTree() if the failure was a transient navigation race
Defensive patterns
Strategy: fallback
Type guard
function canAccessIframe(frame: HTMLIFrameElement): boolean { try { return !!frame.contentDocument } catch { return false } } Prevention
- Expect cross-origin iframes to be skipped; design flows around them
- For extensions, inject into all frames (all_frames: true) and drive each frame separately
- Re-index after iframe navigations settle
When it happens
Trigger: The page embeds a cross-origin iframe (payment widget, embedded ad, third-party app); the iframe navigated or was removed between the frame check and child traversal; sandboxed iframes that deny document access.
Common situations: Login pages with third-party SSO frames; sites embedding Stripe/Stripe-like widgets, ads, or videos; extension contexts where frame origin differs from page origin.
Related errors
AI-assisted analysis of alibaba/page-agent@d02db1ee7c (2026-08-28).
Data as JSON: /api/errors/41517284483ea6d9.
Report an issue: GitHub.