chore: lint

This commit is contained in:
karishmas6
2024-06-01 11:05:45 +05:30
parent 795e653fd0
commit 7c69204f9d

View File

@@ -31,20 +31,20 @@ export class RemoteBrowser {
* used to talk raw Chrome Devtools Protocol. * used to talk raw Chrome Devtools Protocol.
* @private * @private
*/ */
private client : CDPSession | null | undefined = null; private client: CDPSession | null | undefined = null;
/** /**
* Socket.io socket instance enabling communication with the client (frontend) side. * Socket.io socket instance enabling communication with the client (frontend) side.
* @private * @private
*/ */
private socket : Socket; private socket: Socket;
/** /**
* The Playwright's [Page](https://playwright.dev/docs/api/class-page) instance * The Playwright's [Page](https://playwright.dev/docs/api/class-page) instance
* as current interactive remote browser's page. * as current interactive remote browser's page.
* @private * @private
*/ */
private currentPage : Page | null | undefined = null; private currentPage: Page | null | undefined = null;
/** /**
* Interpreter settings for any started interpretation. * Interpreter settings for any started interpretation.
@@ -84,7 +84,7 @@ export class RemoteBrowser {
* @param options remote browser options to be used when launching the browser * @param options remote browser options to be used when launching the browser
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public initialize = async(options: RemoteBrowserOptions) : Promise<void> => { public initialize = async (options: RemoteBrowserOptions): Promise<void> => {
this.browser = <Browser>(await options.browser.launch(options.launchOptions)); this.browser = <Browser>(await options.browser.launch(options.launchOptions));
const context = await this.browser.newContext(); const context = await this.browser.newContext();
this.currentPage = await context.newPage(); this.currentPage = await context.newPage();
@@ -96,10 +96,10 @@ export class RemoteBrowser {
* Should be called only once after the full initialization of the remote browser. * Should be called only once after the full initialization of the remote browser.
* @returns void * @returns void
*/ */
public registerEditorEvents = () : void => { public registerEditorEvents = (): void => {
this.socket.on('rerender', async() => await this.makeAndEmitScreenshot()); this.socket.on('rerender', async () => await this.makeAndEmitScreenshot());
this.socket.on('settings', (settings) => this.interpreterSettings = settings); this.socket.on('settings', (settings) => this.interpreterSettings = settings);
this.socket.on('changeTab', async(tabIndex) => await this.changeTab(tabIndex)); this.socket.on('changeTab', async (tabIndex) => await this.changeTab(tabIndex));
this.socket.on('addTab', async () => { this.socket.on('addTab', async () => {
await this.currentPage?.context().newPage(); await this.currentPage?.context().newPage();
const lastTabIndex = this.currentPage ? this.currentPage.context().pages().length - 1 : 0; const lastTabIndex = this.currentPage ? this.currentPage.context().pages().length - 1 : 0;
@@ -108,7 +108,7 @@ export class RemoteBrowser {
this.socket.on('closeTab', async (tabInfo) => { this.socket.on('closeTab', async (tabInfo) => {
const page = this.currentPage?.context().pages()[tabInfo.index]; const page = this.currentPage?.context().pages()[tabInfo.index];
if (page) { if (page) {
if (tabInfo.isCurrent){ if (tabInfo.isCurrent) {
if (this.currentPage?.context().pages()[tabInfo.index + 1]) { if (this.currentPage?.context().pages()[tabInfo.index + 1]) {
// next tab // next tab
await this.changeTab(tabInfo.index + 1); await this.changeTab(tabInfo.index + 1);
@@ -120,8 +120,8 @@ export class RemoteBrowser {
// close the page and log it // close the page and log it
await page.close(); await page.close();
logger.log( logger.log(
'debug', 'debug',
`${tabInfo.index} page was closed, new length of pages: ${this.currentPage?.context().pages().length}` `${tabInfo.index} page was closed, new length of pages: ${this.currentPage?.context().pages().length}`
) )
} else { } else {
logger.log('error', `${tabInfo.index} index out of range of pages`) logger.log('error', `${tabInfo.index} index out of range of pages`)
@@ -136,10 +136,10 @@ export class RemoteBrowser {
* every time the browser's active page updates. * every time the browser's active page updates.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public subscribeToScreencast = async() : Promise<void> => { public subscribeToScreencast = async (): Promise<void> => {
await this.startScreencast(); await this.startScreencast();
if (!this.client) { if (!this.client) {
logger.log('warn','client is not initialized'); logger.log('warn', 'client is not initialized');
return; return;
} }
this.client.on('Page.screencastFrame', ({ data: base64, sessionId }) => { this.client.on('Page.screencastFrame', ({ data: base64, sessionId }) => {
@@ -147,7 +147,7 @@ export class RemoteBrowser {
setTimeout(async () => { setTimeout(async () => {
try { try {
if (!this.client) { if (!this.client) {
logger.log('warn','client is not initialized'); logger.log('warn', 'client is not initialized');
return; return;
} }
await this.client.send('Page.screencastFrameAck', { sessionId: sessionId }); await this.client.send('Page.screencastFrameAck', { sessionId: sessionId });
@@ -163,14 +163,14 @@ export class RemoteBrowser {
* If an interpretation was running it will be stopped. * If an interpretation was running it will be stopped.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public switchOff = async() : Promise<void> => { public switchOff = async (): Promise<void> => {
await this.interpreter.stopInterpretation(); await this.interpreter.stopInterpretation();
if (this.browser) { if (this.browser) {
await this.stopScreencast(); await this.stopScreencast();
await this.browser.close(); await this.browser.close();
} else { } else {
logger.log('error', 'Browser wasn\'t initialized'); logger.log('error', 'Browser wasn\'t initialized');
logger.log('error','Switching off the browser failed'); logger.log('error', 'Switching off the browser failed');
} }
}; };
@@ -178,7 +178,7 @@ export class RemoteBrowser {
* Makes and emits a single screenshot to the client side. * Makes and emits a single screenshot to the client side.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public makeAndEmitScreenshot = async() : Promise<void> => { public makeAndEmitScreenshot = async (): Promise<void> => {
try { try {
const screenshot = await this.currentPage?.screenshot(); const screenshot = await this.currentPage?.screenshot();
if (screenshot) { if (screenshot) {
@@ -197,7 +197,7 @@ export class RemoteBrowser {
* @param socket socket.io socket instance used to communicate with the client side * @param socket socket.io socket instance used to communicate with the client side
* @returns void * @returns void
*/ */
public updateSocket = (socket: Socket) : void => { public updateSocket = (socket: Socket): void => {
this.socket = socket; this.socket = socket;
this.registerEditorEvents(); this.registerEditorEvents();
this.generator?.updateSocket(socket); this.generator?.updateSocket(socket);
@@ -208,7 +208,7 @@ export class RemoteBrowser {
* Starts the interpretation of the currently generated workflow. * Starts the interpretation of the currently generated workflow.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public interpretCurrentRecording = async () : Promise<void> => { public interpretCurrentRecording = async (): Promise<void> => {
logger.log('debug', 'Starting interpretation in the editor'); logger.log('debug', 'Starting interpretation in the editor');
if (this.generator) { if (this.generator) {
const workflow = this.generator.AddGeneratedFlags(this.generator.getWorkflowFile()); const workflow = this.generator.AddGeneratedFlags(this.generator.getWorkflowFile());
@@ -226,9 +226,9 @@ export class RemoteBrowser {
} }
logger.log('debug', `Starting interpretation with settings: ${JSON.stringify(this.interpreterSettings, null, 2)}`); logger.log('debug', `Starting interpretation with settings: ${JSON.stringify(this.interpreterSettings, null, 2)}`);
await this.interpreter.interpretRecordingInEditor( await this.interpreter.interpretRecordingInEditor(
workflow, this.currentPage, workflow, this.currentPage,
(newPage: Page) => this.currentPage = newPage, (newPage: Page) => this.currentPage = newPage,
this.interpreterSettings this.interpreterSettings
); );
// clear the active index from generator // clear the active index from generator
this.generator.clearLastIndex(); this.generator.clearLastIndex();
@@ -244,7 +244,7 @@ export class RemoteBrowser {
* Stops the workflow interpretation and initializes a new page. * Stops the workflow interpretation and initializes a new page.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public stopCurrentInterpretation = async () : Promise<void> => { public stopCurrentInterpretation = async (): Promise<void> => {
await this.interpreter.stopInterpretation(); await this.interpreter.stopInterpretation();
await this.initializeNewPage(); await this.initializeNewPage();
}; };
@@ -253,7 +253,7 @@ export class RemoteBrowser {
* Returns the current page instance. * Returns the current page instance.
* @returns {Page | null | undefined} * @returns {Page | null | undefined}
*/ */
public getCurrentPage = () : Page | null | undefined => { public getCurrentPage = (): Page | null | undefined => {
return this.currentPage; return this.currentPage;
}; };
@@ -264,12 +264,12 @@ export class RemoteBrowser {
* @param tabIndex index of the page in the pages array on the {@link BrowserContext} * @param tabIndex index of the page in the pages array on the {@link BrowserContext}
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
private changeTab = async (tabIndex: number) : Promise<void>=> { private changeTab = async (tabIndex: number): Promise<void> => {
const page = this.currentPage?.context().pages()[tabIndex]; const page = this.currentPage?.context().pages()[tabIndex];
if (page) { if (page) {
await this.stopScreencast(); await this.stopScreencast();
this.currentPage = page; this.currentPage = page;
await this.currentPage.setViewportSize({height: 720, width: 1280}) await this.currentPage.setViewportSize({ height: 720, width: 1280 })
this.client = await this.currentPage.context().newCDPSession(this.currentPage); this.client = await this.currentPage.context().newCDPSession(this.currentPage);
this.socket.emit('urlChanged', this.currentPage.url()); this.socket.emit('urlChanged', this.currentPage.url());
await this.makeAndEmitScreenshot(); await this.makeAndEmitScreenshot();
@@ -284,10 +284,10 @@ export class RemoteBrowser {
* @param options optional page options to be used when creating a new page * @param options optional page options to be used when creating a new page
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
private initializeNewPage = async (options?: Object) : Promise<void> => { private initializeNewPage = async (options?: Object): Promise<void> => {
await this.stopScreencast(); await this.stopScreencast();
const newPage = options ? await this.browser?.newPage(options) const newPage = options ? await this.browser?.newPage(options)
: await this.browser?.newPage(); : await this.browser?.newPage();
await this.currentPage?.close(); await this.currentPage?.close();
this.currentPage = newPage; this.currentPage = newPage;
@@ -298,7 +298,7 @@ export class RemoteBrowser {
this.client = await this.currentPage.context().newCDPSession(this.currentPage); this.client = await this.currentPage.context().newCDPSession(this.currentPage);
await this.subscribeToScreencast(); await this.subscribeToScreencast();
} else { } else {
logger.log('error', 'Could not get a new page, returned undefined'); logger.log('error', 'Could not get a new page, returned undefined');
} }
}; };
@@ -308,23 +308,23 @@ export class RemoteBrowser {
* Should be called only once after the browser is fully initialized. * Should be called only once after the browser is fully initialized.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
private startScreencast = async() : Promise<void> => { private startScreencast = async (): Promise<void> => {
if (!this.client) { if (!this.client) {
logger.log('warn','client is not initialized'); logger.log('warn', 'client is not initialized');
return; return;
} }
await this.client.send('Page.startScreencast', { format: 'jpeg', quality: 75 }); await this.client.send('Page.startScreencast', { format: 'jpeg', quality: 75 });
logger.log('info',`Browser started with screencasting a page.`); logger.log('info', `Browser started with screencasting a page.`);
}; };
/** /**
* Unsubscribes the current page from the screencast session. * Unsubscribes the current page from the screencast session.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
private stopScreencast = async() : Promise<void> => { private stopScreencast = async (): Promise<void> => {
if (!this.client) { if (!this.client) {
logger.log('error','client is not initialized'); logger.log('error', 'client is not initialized');
logger.log('error','Screencast stop failed'); logger.log('error', 'Screencast stop failed');
} else { } else {
await this.client.send('Page.stopScreencast'); await this.client.send('Page.stopScreencast');
logger.log('info', `Browser stopped with screencasting.`); logger.log('info', `Browser stopped with screencasting.`);
@@ -336,9 +336,9 @@ export class RemoteBrowser {
* @param payload the screenshot binary data * @param payload the screenshot binary data
* @returns void * @returns void
*/ */
private emitScreenshot = (payload: any) : void => { private emitScreenshot = (payload: any): void => {
const dataWithMimeType = ('data:image/jpeg;base64,').concat(payload); const dataWithMimeType = ('data:image/jpeg;base64,').concat(payload);
this.socket.emit('screencast', dataWithMimeType); this.socket.emit('screencast', dataWithMimeType);
logger.log('debug',`Screenshot emitted`); logger.log('debug', `Screenshot emitted`);
}; };
} }