feat: tab management for screencast based on page instance

This commit is contained in:
karishmas6
2024-06-01 11:04:38 +05:30
parent 6bbd71baf4
commit 93585405bf

View File

@@ -257,6 +257,28 @@ export class RemoteBrowser {
return this.currentPage;
};
/**
* Changes the active page to the page instance on the given index
* available in pages array on the {@link BrowserContext}.
* Automatically stops the screencast session on the previous page and starts the new one.
* @param tabIndex index of the page in the pages array on the {@link BrowserContext}
* @returns {Promise<void>}
*/
private changeTab = async (tabIndex: number) : Promise<void>=> {
const page = this.currentPage?.context().pages()[tabIndex];
if (page) {
await this.stopScreencast();
this.currentPage = page;
await this.currentPage.setViewportSize({height: 720, width: 1280})
this.client = await this.currentPage.context().newCDPSession(this.currentPage);
this.socket.emit('urlChanged', this.currentPage.url());
await this.makeAndEmitScreenshot();
await this.subscribeToScreencast();
} else {
logger.log('error', `${tabIndex} index out of range of pages`)
}
}
/**
* Initiates screencast of the remote browser through socket,
* registers listener for rerender event and emits the loaded event.