Skip to content

How to properly handle iframe "swaps" (FrameDetached, Reason "swap")? #558

@0x7357

Description

@0x7357

Environment

Component Version
Node.js v18.12.0
Client (Chrome/Chromium/...) 124.0.6367.79
OS running Node.js Windows 11
OS running the client Windows 11
chrome-remote-interface v0.33.0

Is the client running in a container? NO

Description

I am trying to read all frames via Page.getFrameTree(). It works at the start. The frames are all visible. But after a short moment a FrameDetached, Reason: swap-event is fired.

Now the question is, how to “handle” this correctly?

http://127.0.0.1:9222/json/list shows the correct IFrames. However, Page.getFrameTree() does not - although I would expect it to.

Unfortunately, this topic has not (yet) been dealt with here. Puppeteer seems to have found a way to do this, but I couldn't find the right place in the code base. Probably because Puppeteer pays attention to Target.targetCreated at the same time?

It also feels as if the IFrame is a “separate process”. If I connect directly via CDP({ target: webSocketDebuggerUrl }) (while webSocketDebuggerUrl is the url to the IFrame; parentId is the page which contains that IFrame), then it works.

Example

const CDP = require('chrome-remote-interface');

async function main() {
    // I don't have an example (yet).
}

main().catch((error) => {
  console.error(error);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions