Node updated. Some todos.

This commit is contained in:
Norm Rasmussen
2024-09-23 20:52:09 -04:00
parent 8bfaca8375
commit f25622067f
2041 changed files with 124145 additions and 110445 deletions

View File

@ -39,9 +39,9 @@ const getLogger = (type) => {
class MapperServerCdpConnection {
#cdpConnection;
#bidiSession;
static async create(cdpConnection, mapperTabSource, verbose, mapperOptions) {
static async create(cdpConnection, mapperTabSource, verbose) {
try {
const bidiSession = await this.#initMapper(cdpConnection, mapperTabSource, verbose, mapperOptions);
const bidiSession = await this.#initMapper(cdpConnection, mapperTabSource, verbose);
return new MapperServerCdpConnection(cdpConnection, bidiSession);
}
catch (e) {
@ -96,14 +96,24 @@ class MapperServerCdpConnection {
static #onRuntimeExceptionThrown = (params) => {
debugInfo('exceptionThrown:', params);
};
static async #initMapper(cdpConnection, mapperTabSource, verbose, mapperOptions) {
debugInternal('Initializing Mapper.', mapperOptions);
static async #initMapper(cdpConnection, mapperTabSource, verbose) {
debugInternal('Initializing Mapper.');
const browserClient = await cdpConnection.createBrowserSession();
const { targetId: mapperTabTargetId } = await browserClient.sendCommand('Target.createTarget', {
url: 'about:blank',
});
// Run mapper in the first open tab.
const targets = (await cdpConnection.sendCommand('Target.getTargets', {}));
const mapperTabTargetId = targets.targetInfos.filter((target) => target.type === 'page')[0].targetId;
const { sessionId: mapperSessionId } = await browserClient.sendCommand('Target.attachToTarget', { targetId: mapperTabTargetId, flatten: true });
const mapperCdpClient = cdpConnection.getCdpClient(mapperSessionId);
// Click on the body to interact with the page in order to "beforeunload" being
// triggered when the tab is closed.
await mapperCdpClient.sendCommand('Runtime.evaluate', {
expression: 'document.body.click()',
userGesture: true,
});
// Create and activate new tab with a blank page.
await browserClient.sendCommand('Target.createTarget', {
url: 'about:blank',
});
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));
@ -129,8 +139,9 @@ class MapperServerCdpConnection {
await mapperCdpClient.sendCommand('Runtime.evaluate', {
expression: mapperTabSource,
});
// TODO: handle errors in all these evaluate calls!
await mapperCdpClient.sendCommand('Runtime.evaluate', {
expression: `window.runMapperInstance('${mapperTabTargetId}', ${JSON.stringify(mapperOptions)})`,
expression: `window.runMapperInstance('${mapperTabTargetId}')`,
awaitPromise: true,
});
debugInternal('Mapper is launched!');