Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awaited DOM expression $contentDocument causes js error #338

Open
vihangatheturtle opened this issue Nov 29, 2024 · 3 comments
Open

Awaited DOM expression $contentDocument causes js error #338

vihangatheturtle opened this issue Nov 29, 2024 · 3 comments

Comments

@vihangatheturtle
Copy link

I am using $contentDocument to get the location of an iframe which is redirected once it loads but I get as error on the line with await f.$contentDocument.location.href. It sometimes works though without any error.

const frames = await hero.document.getElementsByTagName("iframe");

for (const f of frames) {
    const frameSource = await f.$contentDocument.location.href;
}

Error:

TypeError: Cannot read properties of undefined (reading 'id')
    at CoreTab.getCoreFrameForMeta (C:\Users\Vihanga\Documents\GitHub\scrape\node_modules\.pnpm\@[email protected]\node_modules\client\lib\CoreTab.ts:238:51)
    at C:\Users\Vihanga\Documents\GitHub\scrape\node_modules\.pnpm\@[email protected]\node_modules\client\lib\DomExtender.ts:206:49
    at async getAwaitedState (C:\Users\Vihanga\Documents\GitHub\scrape\node_modules\.pnpm\@[email protected]\node_modules\client\lib\SetupAwaitedHandler.ts:105:28)
    at async Object.createNodePointer (C:\Users\Vihanga\Documents\GitHub\scrape\node_modules\.pnpm\@[email protected]\node_modules\client\lib\SetupAwaitedHandler.ts:74:54)
    at async AwaitedHandler.createNodePointer (C:\Users\Vihanga\Documents\GitHub\scrape\node_modules\.pnpm\@[email protected]\node_modules\files\2-finalized\awaited-dom\base\AwaitedHandler.ts:33:12)
    at async NodeFactory.createInstanceWithNodePointer (C:\Users\Vihanga\Documents\GitHub\scrape\node_modules\.pnpm\@[email protected]\node_modules\files\2-finalized\awaited-dom\base\NodeFactory.ts:23:19)
@blakebyrnes
Copy link
Contributor

That's an annoying error. There's a high likelihood of frames coming and going, which is likely happening here and just not emitting a meaningful error. Can you try/catch around the $contentDocument line?

@vihangatheturtle
Copy link
Author

Yeah, I will try that thanks

@CHAZICLE
Copy link

CHAZICLE commented Dec 3, 2024

I think I get the same error when I do "await hero.querySelector(iframe).$contentDocument"

/git/hero/build/client/lib/CoreTab.js:156
        if (!this.frameEnvironmentsById.has(frameMeta.id)) {
                                                      ^

TypeError: Cannot read properties of undefined (reading 'id')
    at CoreTab.getCoreFrameForMeta (/git/hero/client/lib/CoreTab.ts:238:51)
    at /git/hero/client/lib/DomExtender.ts:209:26
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Also if I do hero.getFrameEnvironment(hero.querySelector(iframe)) then it returns null but the frame is still clearly in hero.frameEnvironments so it shouldn't be detached.

Very strange. It only happens sometimes for some iframes, but not always.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants