feat: get remote browser current tabs

This commit is contained in:
karishmas6
2024-06-01 11:21:16 +05:30
parent 9c32080d4b
commit 85518848bf

View File

@@ -102,5 +102,23 @@ export const getRemoteBrowserCurrentUrl = (id: string): string | undefined => {
return browserPool.getRemoteBrowser(id)?.getCurrentPage()?.url();
};
/**
* Returns the array of tab strings from a remote browser if exists in the browser pool.
* @param id instance id of the remote browser
* @return {string[] | undefined}
* @category BrowserManagement-Controller
*/
export const getRemoteBrowserCurrentTabs = (id: string): string[] | undefined => {
return browserPool.getRemoteBrowser(id)?.getCurrentPage()?.context().pages()
.map((page) => {
const parsedUrl = new URL(page.url());
const host = parsedUrl.hostname.match(/\b(?!www\.)[a-zA-Z0-9]+/g)?.join('.');
if (host) {
return host;
}
return 'new tab';
});
};
};