"use strict";
/**
 * Copyright: (c) Myia SAS 2026.
 * This file and its contents are licensed under the AGPLv3 License.
 * Please see the LICENSE file at the root of this repository
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildEnterEvent = buildEnterEvent;
// Tolerant page.url() read. Playwright pages throw on closed/detached
// contexts, and any such failure here must not corrupt the trace.
function safePageUrl(currentPage) {
    const pg = currentPage;
    if (!pg || typeof pg.url !== 'function')
        return undefined;
    try {
        return pg.url();
    }
    catch (_) {
        return undefined;
    }
}
function buildEnterEvent(state, meta) {
    const event = {
        type: 'enter',
        seq: ++state.seq,
        parentSeq: state.enterStack.parentSeq(),
        depth: state.enterStack.depth(),
        t: state.clock.now() - state.startedAt,
        wallTime: Date.now(),
        ...meta,
        step: state.stepStack.length ? state.stepStack[state.stepStack.length - 1] : null,
        stepPath: state.stepStack.length ? state.stepStack.slice() : null,
        pageUrl: safePageUrl(state.currentPage),
    };
    state.enterStack.push(event);
    state.exporter.write(event);
}
