"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapPlaywrightPage = exports.wrapPlaywright = exports.PlaywrightController = void 0;
exports.playwrightConfig = playwrightConfig;
const Controller_1 = __importDefault(require("../Controller"));
const mergeChromeArgs_1 = __importDefault(require("../utils/mergeChromeArgs"));
const writeVariables_1 = __importDefault(require("../utils/writeVariables"));
const checkUserArgs_1 = require("../utils/checkUserArgs");
const validateHeadlessPlaywright_1 = __importDefault(require("../utils/validateHeadlessPlaywright"));
function playwrightConfig(opts) {
    const { axe, ...config } = opts;
    let { args = [] } = config;
    (0, validateHeadlessPlaywright_1.default)({
        isPlaywrightTest: false,
        playwrightConfig: opts
    });
    (0, checkUserArgs_1.checkUserArgs)(args);
    (0, writeVariables_1.default)(axe);
    const existingArgs = args;
    args = (0, mergeChromeArgs_1.default)(existingArgs, { disableOtherExtensions: true });
    return {
        ...config,
        args
    };
}
class PlaywrightController extends Controller_1.default {
    constructor(driver) {
        super({
            debugLoggerName: 'PlaywrightController',
            integrationName: 'Playwright',
            configurationFunction: 'playwrightConfig()'
        });
        this.driver = driver;
    }
    async executeScript(fn, ...args) {
        const [arg] = args || [];
        const result = await this.driver.evaluate(fn, arg);
        return result;
    }
    async captureScreenshot() {
        const buffer = await this.driver.screenshot();
        return buffer.toString('base64');
    }
}
exports.PlaywrightController = PlaywrightController;
const wrapPlaywright = (browserContext, playwrightController) => {
    throw new Error(`
    \`wrapPlaywright\` is deprecated and may not work as intended. Please use \`wrapPlaywrightPage\` instead. Example:\n
    let page = await browserContext.newPage()
    const controller = new PlaywrightController(page)
    // Use the new wrapped \`page\` object
    page = wrapPlaywrightPage(page, controller)
  `);
};
exports.wrapPlaywright = wrapPlaywright;
var playwrightWrapping_1 = require("./playwrightWrapping");
Object.defineProperty(exports, "wrapPlaywrightPage", { enumerable: true, get: function () { return playwrightWrapping_1.wrapPage; } });
//# sourceMappingURL=playwright.js.map