A big commit with a bunch of node modules so I could run puppeteer for Walmart. Added some todos and Headway's templates.

This commit is contained in:
Norm Rasmussen
2024-02-28 17:13:10 -05:00
parent dbcdfc8472
commit 1184fe0cd1
1107 changed files with 76526 additions and 8934 deletions

View File

@ -19,7 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapperCdpConnection = void 0;
exports.MapperServerCdpConnection = void 0;
const debug_1 = __importDefault(require("debug"));
const SimpleTransport_js_1 = require("./SimpleTransport.js");
const debugInternal = (0, debug_1.default)('bidi:mapper:internal');
@ -36,32 +36,26 @@ const getLogger = (type) => {
}
return logger;
};
class MapperCdpConnection {
class MapperServerCdpConnection {
#cdpConnection;
#mapperCdpClient;
#bidiSession;
static async create(cdpConnection, mapperTabSource, verbose, mapperOptions) {
try {
const mapperCdpClient = await this.#initMapper(cdpConnection, mapperTabSource, verbose, mapperOptions);
return new MapperCdpConnection(cdpConnection, mapperCdpClient);
const bidiSession = await this.#initMapper(cdpConnection, mapperTabSource, verbose, mapperOptions);
return new MapperServerCdpConnection(cdpConnection, bidiSession);
}
catch (e) {
cdpConnection.close();
throw e;
}
}
constructor(cdpConnection, mapperCdpClient) {
constructor(cdpConnection, bidiSession) {
this.#cdpConnection = cdpConnection;
this.#mapperCdpClient = mapperCdpClient;
this.#bidiSession = new SimpleTransport_js_1.SimpleTransport(async (message) => await this.#sendMessage(message));
this.#mapperCdpClient.on('Runtime.bindingCalled', this.#onBindingCalled);
this.#mapperCdpClient.on('Runtime.consoleAPICalled', this.#onConsoleAPICalled);
// Catch unhandled exceptions in the mapper.
this.#mapperCdpClient.on('Runtime.exceptionThrown', this.#onRuntimeExceptionThrown);
this.#bidiSession = bidiSession;
}
async #sendMessage(message) {
static async #sendMessage(mapperCdpClient, message) {
try {
await this.#mapperCdpClient.sendCommand('Runtime.evaluate', {
await mapperCdpClient.sendCommand('Runtime.evaluate', {
expression: `onBidiMessage(${JSON.stringify(message)})`,
});
}
@ -75,15 +69,15 @@ class MapperCdpConnection {
bidiSession() {
return this.#bidiSession;
}
#onBindingCalled = (params) => {
static #onBindingCalled = (params, bidiSession) => {
if (params.name === 'sendBidiResponse') {
this.#bidiSession.emit('message', params.payload);
bidiSession.emit('message', params.payload);
}
else if (params.name === 'sendDebugMessage') {
this.#onDebugMessage(params.payload);
}
};
#onDebugMessage = (json) => {
static #onDebugMessage = (json) => {
try {
const log = JSON.parse(json);
if (log.logType !== undefined && log.messages !== undefined) {
@ -96,10 +90,10 @@ class MapperCdpConnection {
debugOthers(json);
}
};
#onConsoleAPICalled = (params) => {
static #onConsoleAPICalled = (params) => {
debugInfo('consoleAPICalled: %s %O', params.type, params.args.map((arg) => arg.value));
};
#onRuntimeExceptionThrown = (params) => {
static #onRuntimeExceptionThrown = (params) => {
debugInfo('exceptionThrown:', params);
};
static async #initMapper(cdpConnection, mapperTabSource, verbose, mapperOptions) {
@ -110,6 +104,13 @@ class MapperCdpConnection {
});
const { sessionId: mapperSessionId } = await browserClient.sendCommand('Target.attachToTarget', { targetId: mapperTabTargetId, flatten: true });
const mapperCdpClient = cdpConnection.getCdpClient(mapperSessionId);
const bidiSession = new SimpleTransport_js_1.SimpleTransport(async (message) => await this.#sendMessage(mapperCdpClient, message));
// Process responses from the mapper tab.
mapperCdpClient.on('Runtime.bindingCalled', (params) => this.#onBindingCalled(params, bidiSession));
// Forward console messages from the mapper tab.
mapperCdpClient.on('Runtime.consoleAPICalled', this.#onConsoleAPICalled);
// Catch unhandled exceptions in the mapper.
mapperCdpClient.on('Runtime.exceptionThrown', this.#onRuntimeExceptionThrown);
await mapperCdpClient.sendCommand('Runtime.enable');
await browserClient.sendCommand('Target.exposeDevToolsProtocol', {
bindingName: 'cdp',
@ -133,8 +134,8 @@ class MapperCdpConnection {
awaitPromise: true,
});
debugInternal('Mapper is launched!');
return mapperCdpClient;
return bidiSession;
}
}
exports.MapperCdpConnection = MapperCdpConnection;
exports.MapperServerCdpConnection = MapperServerCdpConnection;
//# sourceMappingURL=MapperCdpConnection.js.map