Skip to content

Commit 26794f8

Browse files
committed
feat: add close method and command to Page class functionality
1 parent d9ffab9 commit 26794f8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pydoll/browser/page.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ async def page_source(self) -> str:
9191
Returns:
9292
str: The source code of the page.
9393
94-
TODO: tix this
9594
"""
9695
response = await self._execute_command(
9796
RuntimeCommands.evaluate_script(
@@ -100,6 +99,12 @@ async def page_source(self) -> str:
10099
)
101100
return response['result']['result']['value']
102101

102+
async def close(self):
103+
"""
104+
Closes the page.
105+
"""
106+
await self._execute_command(PageCommands.close())
107+
103108
async def get_cookies(self) -> list[dict]:
104109
"""
105110
Retrieves the cookies of the page.

pydoll/commands/page.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class PageCommands:
3131
'params': {},
3232
}
3333
HANDLE_DIALOG = {'method': 'Page.handleJavaScriptDialog', 'params': {}}
34+
CLOSE = {'method': 'Page.close'}
3435

3536
@classmethod
3637
def handle_dialog(cls, accept: bool = True) -> dict:
@@ -173,3 +174,14 @@ def disable_page(cls) -> dict:
173174
containing the method to disable the Page domain.
174175
"""
175176
return cls.DISABLE_PAGE
177+
178+
@classmethod
179+
def close(cls) -> dict:
180+
"""
181+
Generates the command to close the current page.
182+
183+
Returns:
184+
dict: The command to be sent to the browser,
185+
containing the method to close the current page.
186+
"""
187+
return cls.CLOSE

0 commit comments

Comments
 (0)