UNPKG

allproxy

Version:

AllProxy: MITM HTTP Debugging Tool.

71 lines 2.94 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HideWarningServer = void 0; const mockttp_1 = require("mockttp"); const constants_1 = require("./constants"); // The first tab that opens in a new Chrome/Edge window warns about dangerous flags. // Closing it and immediately opening a new one is a bit cheeky, but // is completely gets rid that, more or less invisibly: class HideWarningServer { constructor( // @ts-ignore config) { this.config = config; this.server = (0, mockttp_1.getLocal)(); // Resolved once the server has seen at least once // request for the warning-hiding page. this.completedPromise = new Promise((resolve) => { this.server.on('request', (req) => { if (req.url.includes('hide-warning')) { resolve(); } }); }); } start(targetUrl) { return __awaiter(this, void 0, void 0, function* () { yield this.server.start(constants_1.EPHEMERAL_PORT_RANGE); yield this.server.forGet('/hide-warning').thenReply(200, ` <html> <title>HTTP Toolkit Warning Fix</title> <meta charset="UTF-8" /> <style> body { background-color: #d8e2e6; } </style> <script> const targetUrl = ${JSON.stringify(targetUrl)}; window.open(targetUrl, '_blank'); window.close(); </script> <body> This page should disappear momentarily. If it doesn't, click <a href="${targetUrl}">this link</a> </body> </html> `, { "content-type": "text/html" }); }); } get host() { return this.server.url .replace('https://', ''); } get hideWarningUrl() { return this.server.url.replace(/\/?$/, '/hide-warning'); } stop() { return __awaiter(this, void 0, void 0, function* () { yield this.server.stop(); }); } } exports.HideWarningServer = HideWarningServer; //# sourceMappingURL=hide-warning-server.js.map