question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Retrieving call frames from inside iframe

See original GitHub issue

I’m trying to retrieve call frames from a script that is embedded inside an iframe. How would I do this? I’m trying to debug hcaptcha on https://www.epicgames.com/id/login/epic

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

CDP(async (client) => {
    try {
        const {Debugger, Page, Runtime} = client;
        // enable debugger domain
        await Debugger.enable();
        await Runtime.enable();

        Debugger.paused(async({asyncStackTrace, callFrames}) => {
            //console.log(`PAUSED at line ${callFrames[0].location.lineNumber + 1}`); // (zero-based)
            try {
            //console.log(callFrames[0].scopeChain[0].object);
            //var tg = promise
            var frame = callFrames[0];
            var local = await Runtime.getProperties(callFrames[0].scopeChain[0].object);
            var localScope = local["result"];

            localScope.forEach(element => {
                console.log(element)
            });

            var result = {
                "frame": frame,
                "scope": localScope,
            }

            console.log(JSON.stringify(result));

            } catch (e) {
                console.log(e)
            }
        });

    } catch (err) {
        console.error(err);
    }
}).on('error', (err) => {
    console.error(err);
});

If you login once, you should see new scripts get loaded which are hcaptcha, but when I breakpoint it doesn’t output anything. My guess is that it is due to the iframe. Is there any solution? Apologies if this is worded badly, it’s very late.

Component Version
Operating system Windows 10
Node.js 14.18.0
Chrome/Chromium/… Chrome 96.0.4664.45
chrome-remote-interface 0.31.1

Is Chrome running in a container? NO

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cyrus-andcommented, Dec 13, 2021

OK the reason why your scenario doesn’t get handled really escapes me; I cannot reproduce it in a standalone PoC, I tried several things, including creating the frame dynamically, etc. It feels like a Chrome bug honestly…

Anyway, you can try this workaround:

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

(async () => {
    const client = await CDP();
    const {Page, Target} = client;

    Target.attachedToTarget(async ({targetInfo: {targetId}}) => {
        const client = await CDP({target: `ws://127.0.0.1:9222/devtools/page/${targetId}`});
        const {Debugger} = client;

        Debugger.paused(async ({callFrames}) => {
            console.log('BREAK');

            for (const frame of callFrames) {
                console.log('FRAME', frame);
            }
        });

        await Debugger.enable();
    });

    await Target.setAutoAttach({
        autoAttach: true,
        waitForDebuggerOnStart: false
    });

    await Page.navigate({url: 'https://www.epicgames.com/id/login/epic'});
})();

Basically, for each discovered target creates another instance in which it performs the logic, i.e., dumping the stack frames. This shouldn’t be needed but still…

0reactions
cyrus-andcommented, Dec 15, 2021

Awesome! If you ever come up with a minimal PoC that reproduces this issue, feel free to post it here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Get element from within an iFrame - Stack Overflow
The trick here is jQuery's .contents() method, unlike .children() which can only get HTML elements, .contents() can get both text nodes and HTML ......
Read more >
Working with iframes in Cypress
Application with iframe · Clicking on a button inside the iframe · Slow-loading frames · Custom command · Spying on window.fetch · Ajax...
Read more >
HTMLIFrameElement.contentWindow - Web APIs | MDN
The contentWindow property returns the Window object of an HTMLIFrameElement. You can use this Window object to access the iframe's document ...
Read more >
How to handle iFrame in Selenium - BrowserStack
Learn how to handle iframe in Selenium with the SwitchTo() method to switch between frames along with code samples.
Read more >
Cannot get element inside Iframe. · Issue #6 · go-rod ... - GitHub
I see people encounter similar issues all the time. Such as when an iframe is inside another iframe you need to call Frame()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found