"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InspectedPage = void 0;
exports.setupInspectedPage = setupInspectedPage;
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const chai_1 = require("chai");
const page_wrapper_js_1 = require("./page-wrapper.js");
class InspectedPage extends page_wrapper_js_1.PageWrapper {
    serverPort;
    constructor(page, serverPort) {
        super(page);
        this.serverPort = serverPort;
        this.serverPort = serverPort;
    }
    async goTo(url, options = {}) {
        await this.page.goto(url, options);
    }
    async goToHtml(unparsedHtml) {
        let html = unparsedHtml;
        if (!html.trim().startsWith('<!DOCTYPE html>')) {
            html = `<!DOCTYPE html>${html}`;
        }
        return await this.goTo(`data:text/html;charset=utf-8,${encodeURIComponent(html)}`);
    }
    waitForSelector(selector, options) {
        return this.page.waitForSelector(selector, options);
    }
    async goToResource(path, options = {}) {
        await this.goTo(`${this.getResourcesPath()}/${path}`, options);
    }
    async goToResourceWithCustomHost(host, path) {
        chai_1.assert.isTrue(host.endsWith('.test'), 'Only custom hosts with a .test domain are allowed.');
        await this.goTo(`${this.getResourcesPath(host)}/${path}`);
    }
    getResourcesPath(host = 'localhost') {
        return `${this.domain(host)}/test/e2e/resources`;
    }
    domain(host = 'localhost') {
        return `https://${host}:${this.serverPort}`;
    }
    getOopifResourcesPath() {
        return this.getResourcesPath('devtools.oopif.test');
    }
    async overridePermissions(permissions) {
        await this.page.browserContext().overridePermissions(`https://localhost:${this.serverPort}`, permissions);
    }
}
exports.InspectedPage = InspectedPage;
async function setupInspectedPage(context, serverPort) {
    const page = await context.newPage();
    return new InspectedPage(page, serverPort);
}
//# sourceMappingURL=target-helper.js.map