Skip to content

Clicking inside an iframe? #553

@BeatBroccoli

Description

@BeatBroccoli

Environment

Component Version
Node.js v20.11.1
Client (Chrome/Chromium/...) Google Chrome 122
OS running Node.js Windows 11
OS running the client Windows 11
chrome-remote-interface 0.33.0

Is the client running in a container? NO

Description

Hi, sometimes i cant evaluate scripts inside an iframe. The context doesnt show up.
If I open devtools i cant cleary see there is an context but the protocol doesnt provide access to it, at least not via
Runtime.executionContextCreated

Example

import * as chromeLauncher from 'chrome-launcher';
import CDP, * as cri from 'chrome-remote-interface';

(async () => {

    let chrome = await chromeLauncher.launch({ port: 9500 });
    let client = await cri.default({ port: chrome.port });

    const { Runtime, Page, Target } = client;
    await Promise.all([Page.enable(), Runtime.enable()]);
    await Target.setAutoAttach({ autoAttach: true, waitForDebuggerOnStart: false });

    Runtime.executionContextCreated(async (evt) => {
        await Runtime.callFunctionOn({
            executionContextId: evt.context.id,
            functionDeclaration: 'function() { alert(document.location.href); let $box = document.querySelector("input"); if($box) $box.click(); return $box; }'
        });
    });

    await Target.targetCreated(({ targetInfo }) => { console.log(`New target created: ${targetInfo.url}`); });
    await Page.navigate({ url: 'https://nopecha.com/demo/cloudflare' });

})();

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