"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHtmlCollectionHook = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
const utils_1 = require("../utils");
async function createHtmlCollectionHook(page) {
    const session = await utils_1.getChromeCDPSession(page);
    if (!session) {
        return async () => undefined;
    }
    return async function htmlCollectionHook({ testContext }) {
        var _a;
        const { data: mhtmlContent } = await utils_1.sendCDPMessage(session, 'Page.captureSnapshot', {
            format: 'mhtml',
        });
        const mhtmlFile = `${(_a = testContext.currentStep) === null || _a === void 0 ? void 0 : _a.index}.document.mhtml`;
        const outputFilePath = path_1.join(testContext.testArtifactsFolder, mhtmlFile);
        await fs_1.promises.writeFile(outputFilePath, mhtmlContent);
        testContext.addStepMetadata({ mhtmlFile });
    };
}
exports.createHtmlCollectionHook = createHtmlCollectionHook;
