Skip to content

Commit b5d014b

Browse files
authored
Merge pull request #26 from thalissonvs/feat/handle-pages
feat: add method to retrieve Page instance by its ID in Browser class
2 parents 683dacd + d9ffab9 commit b5d014b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pydoll/browser/base.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ async def set_download_path(self, path: str):
9494
"""
9595
await self._execute_command(BrowserCommands.set_download_path(path))
9696

97+
async def get_page_by_id(self, page_id: str) -> Page:
98+
"""
99+
Retrieves a Page instance by its ID.
100+
101+
Args:
102+
page_id (str): The ID of the page to retrieve.
103+
104+
Returns:
105+
Page: The Page instance corresponding to the specified ID.
106+
"""
107+
return Page(self._connection_port, page_id)
108+
97109
async def get_page(self) -> Page:
98110
"""
99111
Retrieves a Page instance for an existing page in the browser.
@@ -173,7 +185,7 @@ async def new_page(self, url: str = ''):
173185
page_id = response['result']['targetId']
174186
return page_id
175187

176-
async def _get_targets(self):
188+
async def get_targets(self):
177189
"""
178190
Retrieves the list of open pages in the browser.
179191
@@ -412,7 +424,7 @@ async def _continue_request_auth_required(
412424
await self.disable_fetch_events()
413425

414426
async def _init_first_page(self):
415-
pages = await self._get_targets()
427+
pages = await self.get_targets()
416428
valid_page = await self._get_valid_page(pages)
417429
self._pages.append(valid_page)
418430

0 commit comments

Comments
 (0)