kayle
Version:
Extremely fast and accurate accessibility engine built for any headless tool like playwright or puppeteer.
47 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.goToPage = exports.setNetworkInterception = exports.setCDPIntercept = exports.getCdp = void 0;
const cdp_blocking_1 = require("./cdp-blocking");
const getCdp = (o) => {
const cdpSession = o.cdpSession
? o.cdpSession
: o?.page?._client &&
typeof o.page._client === "function" &&
o.page._client();
return cdpSession;
};
exports.getCdp = getCdp;
const setCDPIntercept = async (o) => {
const cdpSession = (0, exports.getCdp)(o);
if (!cdpSession) {
try {
o.cdpSession = await o.page.context().newCDPSession(o.page);
}
catch (e) {
console.error(e);
}
}
await (0, cdp_blocking_1.sendCDPPageConfigurationEnable)(o.cdpSession ?? cdpSession, o);
};
exports.setCDPIntercept = setCDPIntercept;
const setNetworkInterception = async (o) => await (0, exports.setCDPIntercept)(o);
exports.setNetworkInterception = setNetworkInterception;
const goToPage = async (o) => {
await (0, exports.setCDPIntercept)(o);
const { page, timeout, waitUntil, origin } = o;
let valid = false;
try {
const res = await page.goto(origin || "http://localhost", {
timeout: timeout ?? 0,
waitUntil: waitUntil ?? "domcontentloaded",
});
if (res) {
valid = res.status() === 304 || res.ok();
}
}
catch (e) {
}
return valid;
};
exports.goToPage = goToPage;
//# sourceMappingURL=go-to-page.js.map