Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions examples/fundamentals__chrome-remote-debugging/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,34 @@ module.exports = defineConfig({
await client.DOM.enable()
await client.CSS.enable()

// as the Window consists of two IFrames, we must retrieve the right one
// The window contains multiple same-origin iframes (e.g. the reporter
// frame and the app frame), so find the one that actually holds the
// element rather than assuming a fixed position.
const allRootNodes = await client.DOM.getFlattenedDocument()

const isIframe = (node) => {
return node.nodeName === 'IFRAME' && node.contentDocument
}

const filtered = allRootNodes.nodes.filter(isIframe)
const frames = allRootNodes.nodes.filter(isIframe)

// The first IFrame is our App
const root = filtered[0].contentDocument
let nodeId

const { nodeId } = await client.DOM.querySelector({
nodeId: root.nodeId,
selector,
})
for (const frame of frames) {
const { nodeId: found } = await client.DOM.querySelector({
nodeId: frame.contentDocument.nodeId,
selector,
})

if (found) {
nodeId = found
break
}
}

if (!nodeId) {
throw new Error(`Could not find an iframe containing selector: ${selector}`)
}

return client.CSS.forcePseudoState({
nodeId,
Expand Down