Skip to content

Commit f63da12

Browse files
Samiya CaurDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Update prompt so that it is better able to detect when inspected element is in a shadow DOM
Pending: how to apply changes for such elements Bug: 361746671 Change-Id: I4923d8ec82e6d1b5670f84897729fb6a2858772a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6163943 Commit-Queue: Samiya Caur <[email protected]> Reviewed-by: Alex Rudenko <[email protected]>
1 parent 3354660 commit f63da12

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

front_end/panels/ai_assistance/agents/StylingAgent.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ c`;
467467
* It has a next sibling and it is an element node
468468
* It has a previous sibling and it is a non element node
469469
* Its parent's selector is \`div#grandparentElement\`
470+
* Its parent is a non element node
470471
* Its parent has only 1 child element node
471472
* Its parent has only 1 child text node`;
472473

front_end/panels/ai_assistance/agents/StylingAgent.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ The user selected a DOM element in the browser's DevTools and sends a query abou
5454
# Considerations
5555
* After applying a fix, please ask the user to confirm if the fix worked or not.
5656
* Meticulously investigate all potential causes for the observed behavior before moving on. Gather comprehensive information about the element's parent, siblings, children, and any overlapping elements, paying close attention to properties that are likely relevant to the query.
57+
* Be aware of the different node types (element, text, comment, document fragment, etc.) and their properties. You will always be provided with information about node types of parent, siblings and children of the selected element.
5758
* Avoid making assumptions without sufficient evidence, and always seek further clarification if needed.
5859
* Always explore multiple possible explanations for the observed behavior before settling on a conclusion.
5960
* When presenting solutions, clearly distinguish between the primary cause and contributing factors.
6061
* Please answer only if you are sure about the answer. Otherwise, explain why you're not able to answer.
6162
* When answering, always consider MULTIPLE possible solutions.
6263
* You're also capable of executing the fix for the issue user mentioned. Reflect this in your suggestions.
6364
* Use \`window.getComputedStyle\` to gather **rendered** styles and make sure that you take the distinction between authored styles and computed styles into account.
64-
* **CRITICAL** Call \`window.getComputedStyle\` only once per element and store results into a local variable. Never try to return all the styles of the element in \`data\`. Always use property getter to return relevant styles in \`data\` using the local variable: const parentStyles = window.getComputedStyle($0.parentElement); const data = { parentElementColor: parentStyles['color']}.
65+
* **CRITICAL** Call \`window.getComputedStyle\` only once per element and store results into a local variable. Never try to return all the styles of the element in \`data\`. Always use property getter to return relevant styles in \`data\` using the local variable: const styles = window.getComputedStyle($0); const data = { elementColor: styles['color']}.
6566
* **CRITICAL** Never assume a selector for the elements unless you verified your knowledge.
6667
* **CRITICAL** Consider that \`data\` variable from the previous ACTION blocks are not available in a different ACTION block.
6768
* **CRITICAL** If the user asks a question about religion, race, politics, sexuality, gender, or other sensitive topics, answer with "Sorry, I can't answer that. I'm best at questions about debugging web pages."
@@ -545,10 +546,19 @@ export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
545546
output += `\n* It has a previous sibling and it is ${elementOrNodeElementNodeText} node`;
546547
}
547548

549+
if (element.isInShadowTree()) {
550+
output += '\n* It is in a shadow DOM tree.';
551+
}
552+
548553
const parentNode = element.parentNode;
549554
if (parentNode) {
550555
const parentChildrenNodes = await parentNode.getChildNodesPromise();
551556
output += `\n* Its parent's selector is \`${parentNode.simpleSelector()}\``;
557+
const elementOrNodeElementNodeText = parentNode.nodeType() === Node.ELEMENT_NODE ? 'an element' : 'a non element';
558+
output += `\n* Its parent is ${elementOrNodeElementNodeText} node`;
559+
if (parentNode.isShadowRoot()) {
560+
output += '\n* Its parent is a shadow root.';
561+
}
552562
if (parentChildrenNodes) {
553563
const childElementNodes =
554564
parentChildrenNodes.filter(siblingNode => siblingNode.nodeType() === Node.ELEMENT_NODE);

0 commit comments

Comments
 (0)