66 lines
8.1 KiB
JavaScript
66 lines
8.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getRequestId = exports.createRequestPausedEventForResponse = exports.isPreflightRequest = exports.isRequestPausedEvent = exports.isUnauthorized = exports.isRequest = exports.dispatchEvent = exports.navigateTo = exports.redirect = void 0;
|
|
const http_status_codes_1 = require("http-status-codes");
|
|
const headers_1 = require("./headers");
|
|
const types_1 = require("../types");
|
|
async function redirect(client, requestId, url) {
|
|
await client.Fetch.fulfillRequest({
|
|
requestId,
|
|
responseCode: http_status_codes_1.StatusCodes.MOVED_PERMANENTLY,
|
|
responseHeaders: [
|
|
{ name: 'location', value: url },
|
|
],
|
|
});
|
|
}
|
|
exports.redirect = redirect;
|
|
async function navigateTo(client, url) {
|
|
await client.Page.navigate({ url });
|
|
}
|
|
exports.navigateTo = navigateTo;
|
|
async function dispatchEvent(client, type, options) {
|
|
switch (+type) {
|
|
case types_1.EventType.Mouse:
|
|
await client.Input.dispatchMouseEvent(options);
|
|
break;
|
|
case types_1.EventType.Key:
|
|
await client.Input.dispatchKeyEvent(options);
|
|
break;
|
|
case types_1.EventType.Touch:
|
|
await client.Input.dispatchTouchEvent(options);
|
|
break;
|
|
default:
|
|
throw new Error(`Unknown "${options.type}" event type`);
|
|
}
|
|
}
|
|
exports.dispatchEvent = dispatchEvent;
|
|
function isRequest(event) {
|
|
return event.responseStatusCode === void 0;
|
|
}
|
|
exports.isRequest = isRequest;
|
|
function isUnauthorized(statusCode) {
|
|
return statusCode === 401;
|
|
}
|
|
exports.isUnauthorized = isUnauthorized;
|
|
function isRequestPausedEvent(val) {
|
|
return val && val.frameId && typeof val.request === 'object';
|
|
}
|
|
exports.isRequestPausedEvent = isRequestPausedEvent;
|
|
function isPreflightRequest(event) {
|
|
return event.request.method === 'OPTIONS';
|
|
}
|
|
exports.isPreflightRequest = isPreflightRequest;
|
|
function createRequestPausedEventForResponse(mockedResponse, requestEvent) {
|
|
return Object.assign({}, requestEvent, {
|
|
responseStatusCode: mockedResponse.statusCode,
|
|
responseHeaders: (0, headers_1.convertToHeaderEntries)(mockedResponse.headers),
|
|
});
|
|
}
|
|
exports.createRequestPausedEventForResponse = createRequestPausedEventForResponse;
|
|
function getRequestId(event) {
|
|
if (isRequestPausedEvent(event))
|
|
return event.networkId;
|
|
return event.frame.loaderId;
|
|
}
|
|
exports.getRequestId = getRequestId;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2RwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3Byb3h5bGVzcy91dGlscy9jZHAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQ0EseURBQWdEO0FBS2hELHVDQUFtRDtBQUNuRCxvQ0FBcUM7QUFHOUIsS0FBSyxVQUFVLFFBQVEsQ0FBRSxNQUFtQixFQUFFLFNBQWlCLEVBQUUsR0FBVztJQUMvRSxNQUFNLE1BQU0sQ0FBQyxLQUFLLENBQUMsY0FBYyxDQUFDO1FBQzlCLFNBQVM7UUFDVCxZQUFZLEVBQUssK0JBQVcsQ0FBQyxpQkFBaUI7UUFDOUMsZUFBZSxFQUFFO1lBQ2IsRUFBRSxJQUFJLEVBQUUsVUFBVSxFQUFFLEtBQUssRUFBRSxHQUFHLEVBQUU7U0FDbkM7S0FDSixDQUFDLENBQUM7QUFDUCxDQUFDO0FBUkQsNEJBUUM7QUFFTSxLQUFLLFVBQVUsVUFBVSxDQUFFLE1BQW1CLEVBQUUsR0FBVztJQUM5RCxNQUFNLE1BQU0sQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDLEVBQUUsR0FBRyxFQUFFLENBQUMsQ0FBQztBQUN4QyxDQUFDO0FBRkQsZ0NBRUM7QUFFTSxLQUFLLFVBQVUsYUFBYSxDQUFFLE1BQW1CLEVBQUUsSUFBZSxFQUFFLE9BQVk7SUFDbkYsUUFBUSxDQU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