[WIP] Extend more abstract functions and classes using API#24
[WIP] Extend more abstract functions and classes using API#24
Conversation
Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
Co-authored-by: P4X-ng <223870169+P4X-ng@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a1cb466fb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Get the text content of the element. | ||
|
|
||
| :return: Text content | ||
| """ | ||
| outer_html = await self.session.execute(dom.get_outer_html(self.node_id)) |
There was a problem hiding this comment.
Return text content instead of outer HTML
get_text_content promises text but returns dom.get_outer_html, which includes tags/attributes; any caller expecting plain text (e.g., comparing "Hello") will instead get "<span>Hello</span>" and similar markup. This makes the method unreliable for text extraction and breaks consumers when elements have nested tags. Consider using textContent via runtime.call_function_on or a dedicated CDP call so the method name matches behavior.
Useful? React with 👍 / 👎.
| await self.press(char, delay) | ||
| if delay > 0: | ||
| import trio | ||
| await trio.sleep(delay) |
There was a problem hiding this comment.
Double delay in Keyboard.type() method
Medium Severity
The Keyboard.type() method applies the delay twice per character. It passes delay to press() which uses it as the keydown-to-keyup hold time, then calls trio.sleep(delay) again after each press. The documentation states the delay is "Time to wait between key presses" but the actual behavior doubles this time: once during press() and once after. If a user specifies delay=0.1, each character takes 0.2 seconds instead of the expected 0.1 second gap between presses. The call to press(char, delay) should likely be press(char) without passing the delay.
| target_id = t.target_id | ||
| break | ||
|
|
||
| logger.info('Attaching to target id=%s', target_id) |
There was a problem hiding this comment.
Undefined variable if no matching target found
Medium Severity
The target_id variable is only assigned inside the for loop when a matching target is found. If targets is empty or no target matches the criteria (e.g., all pages are attached or are devtools pages), target_id is never assigned. When line 46 attempts to use target_id, this causes a NameError crash with an unhelpful error message rather than a clear explanation that no suitable target was found.
Additional Locations (1)
| # This is a simplified approach - in production you might want to use | ||
| # runtime evaluation for more accurate text extraction | ||
| # For now, return the HTML (caller can parse it if needed) | ||
| return outer_html |
There was a problem hiding this comment.
get_text_content returns HTML not text content
Medium Severity
The get_text_content() method is named and documented as returning "text content" but actually returns outer HTML via dom.get_outer_html(). Code using this method expecting plain text (e.g., for string comparison like if text == "Submit") will fail because it receives HTML markup like <button>Submit</button> instead. The implementation contradicts the function's name, return type documentation, and all external docs that describe it as extracting text content.
Add higher-level utility functions and classes to trio-chrome-devtools-protocol
This PR addresses issue about extending the library with more abstract functions and classes for common browser automation tasks, inspired by Puppeteer/Pyppeteer.
✅ Completed
Core Implementation
trio_cdp/util.pymodule for higher-level utility functionsquery_selector()- Find element by CSS selectorquery_selector_all()- Find all matching elementswait_for_selector()- Wait for element to appearDocumentation & Examples
Testing & Quality
🎯 Key Features
Keyboard Class
down(),up(),press()- Individual key eventstype()- Type a string character by characterMouse Class
move()- Move mouse with smooth interpolationclick(),down(),up()- Mouse button eventsElementHandle Class
click()- Click on element at its centertype()- Focus and type into elementget_attribute()- Get HTML attributesget_property()- Get JavaScript propertiesget_text_content()- Extract text content🏆 Design Principles
All utilities maintain the library's core principles:
📚 Decision
Utilities are integrated into the main package rather than creating a separate
trio-puppeteermodule, as they are lightweight and tightly coupled with CDP concepts.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Note
Introduces documentation and examples for new high-level utilities and updates tooling/deps.
docs/utilities.rst), links them indocs/index.rst, and expandsREADME.mdwith features and a utilities exampleexamples/form_interaction.pyandexamples/keyboard_mouse.pyshowcasing keyboard/mouse and element interactionsUTILITIES_IMPLEMENTATION.mdsummarizing the utilities design and scopegenerator/generate.pyto formattyping.Optionalannotationspoetry.lockwith broad dependency updatesWritten by Cursor Bugbot for commit 7a1cb46. Configure here.