81 lines
2.4 KiB
TypeScript
81 lines
2.4 KiB
TypeScript
|
|
import {
|
||
|
|
Page,
|
||
|
|
Browser,
|
||
|
|
CDPSession,
|
||
|
|
BrowserContext,
|
||
|
|
} from 'playwright';
|
||
|
|
import { Socket } from "socket.io";
|
||
|
|
|
||
|
|
import logger from '../../logger';
|
||
|
|
import { InterpreterSettings, RemoteBrowserOptions } from "../../types";
|
||
|
|
import { WorkflowGenerator } from "../../workflow-management/classes/Generator";
|
||
|
|
import { WorkflowInterpreter } from "../../workflow-management/classes/Interpreter";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This class represents a remote browser instance.
|
||
|
|
* It is used to allow a variety of interaction with the Playwright's browser instance.
|
||
|
|
* Every remote browser holds an instance of a generator and interpreter classes with
|
||
|
|
* the purpose of generating and interpreting workflows.
|
||
|
|
* @category BrowserManagement
|
||
|
|
*/
|
||
|
|
export class RemoteBrowser {
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Playwright's [browser](https://playwright.dev/docs/api/class-browser) instance.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private browser: Browser | null = null;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The Playwright's [CDPSession](https://playwright.dev/docs/api/class-cdpsession) instance,
|
||
|
|
* used to talk raw Chrome Devtools Protocol.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private client : CDPSession | null | undefined = null;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Socket.io socket instance enabling communication with the client (frontend) side.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private socket : Socket;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The Playwright's [Page](https://playwright.dev/docs/api/class-page) instance
|
||
|
|
* as current interactive remote browser's page.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private currentPage : Page | null | undefined = null;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Interpreter settings for any started interpretation.
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
private interpreterSettings: InterpreterSettings = {
|
||
|
|
debug: false,
|
||
|
|
maxConcurrency: 1,
|
||
|
|
maxRepeats: 1,
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* {@link WorkflowGenerator} instance specific to the remote browser.
|
||
|
|
*/
|
||
|
|
public generator: WorkflowGenerator;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* {@link WorkflowInterpreter} instance specific to the remote browser.
|
||
|
|
*/
|
||
|
|
public interpreter: WorkflowInterpreter;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Initializes a new instances of the {@link Generator} and {@link WorkflowInterpreter} classes and
|
||
|
|
* assigns the socket instance everywhere.
|
||
|
|
* @param socket socket.io socket instance used to communicate with the client side
|
||
|
|
* @constructor
|
||
|
|
*/
|
||
|
|
public constructor(socket: Socket) {
|
||
|
|
this.socket = socket;
|
||
|
|
this.interpreter = new WorkflowInterpreter(socket);
|
||
|
|
this.generator = new WorkflowGenerator(socket);
|
||
|
|
}
|
||
|
|
}
|