Skip to content

Calling await hero.mainFrameEnvironment.document before await hero.goto causes succeeding call to await currFrame.getFrameEnvironment to return null #397

Description

@justinearl

Calling await hero.mainFrameEnvironment.document before await hero.goto causes succeeding call to await currFrame.getFrameEnvironment to return null

Code to replicate

import Hero, { IHeroCreateOptions } from "@ulixee/hero"
import { assert } from "node:console";

const TIMEOUT_MS = 100000

async function createHero(): Promise<Hero> {
    const heroOptions: IHeroCreateOptions = {connectionToCore: {host: "localhost:1818"}}
    const hero = new Hero(heroOptions)
    return hero
}

async function GetFrameEnvironment(hero: Hero) {
    await hero.goto("https://the-internet.herokuapp.com/nested_frames", {timeoutMs: TIMEOUT_MS})
    await hero.waitForPaintingStable({ timeoutMs: TIMEOUT_MS })
    const currFrame = hero.mainFrameEnvironment
    const framElem = currFrame.querySelector("[name=frame-top]")
    const frameEnv = await currFrame.getFrameEnvironment(framElem)
    assert (frameEnv !== null, "FrameEnv is null")
}

async function CallMainFrameEnvironmentBeforeGoto() {
    const hero = await createHero()
    await hero.mainFrameEnvironment.document  // This causes the getFrameEnvironment to return `null`
    await GetFrameEnvironment(hero)
    await hero.close()
}

async function NormalFlow() {
    const hero = await createHero()
    await GetFrameEnvironment(hero)
    await hero.close()
}

async function main() {
    console.log("Normal flow")
    await NormalFlow()
    console.log("Testing Failing Case")
    await CallMainFrameEnvironmentBeforeGoto()
}

main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions