Skip to content

Commit f36d656

Browse files
jackfranklindevtools-frontend-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
Exclude hover button labels from console copy
Console messages use a custom DOM traversal to extract text for copying. By using CSS pseudo-elements for the button labels instead of actual text nodes, we ensure they are not picked up by this traversal. Fixed: 496425912 Change-Id: Id710241850279ba4e4a18d85185fbe409ec4eba7 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7766591 Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Kim-Anh Tran <kimanh@chromium.org> Reviewed-by: Kim-Anh Tran <kimanh@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
1 parent b9b20ea commit f36d656

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

front_end/panels/console/ConsoleViewMessage.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ describeWithMockConnection('ConsoleViewMessage', () => {
170170
const messageElement =
171171
createMessage(Common.Console.FrontendMessageSource.ConsoleAPI, Protocol.Log.LogEntryLevel.Error, 'got here');
172172
const button = messageElement.querySelector('[aria-label=\'Understand this error. Powered by AI.\']');
173-
assert.strictEqual(button?.textContent, 'Understand this error');
173+
assert.strictEqual(
174+
button?.querySelector('.button-label div')?.getAttribute('data-text'), 'Understand this error');
174175
});
175176

176177
it('creates teaser on hover', () => {

front_end/panels/console/ConsoleViewMessage.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,10 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
15921592
const label = document.createElement('div');
15931593
label.classList.add('button-label');
15941594
const text = document.createElement('div');
1595-
text.innerText = this.getExplainLabel();
1595+
// We use a data attribute and a CSS pseudo-element for the button label
1596+
// to prevent the text from being picked up by the console's custom
1597+
// copy-to-clipboard traversal, which only collects actual text nodes.
1598+
text.setAttribute('data-text', this.getExplainLabel());
15961599
label.append(text);
15971600
button.append(label);
15981601
button.classList.add('hover-button');
@@ -1615,7 +1618,10 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
16151618
const label = document.createElement('div');
16161619
label.classList.add('button-label');
16171620
const text = document.createElement('div');
1618-
text.innerText = 'Debug with breakpoint AI';
1621+
// We use a data attribute and a CSS pseudo-element for the button label
1622+
// to prevent the text from being picked up by the console's custom
1623+
// copy-to-clipboard traversal, which only collects actual text nodes.
1624+
text.setAttribute('data-text', 'Debug with breakpoint AI');
16191625
label.append(text);
16201626
button.append(label);
16211627
button.classList.add('hover-button');

front_end/panels/console/consoleView.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@
615615
& div {
616616
display: inline-block;
617617
vertical-align: -1px;
618+
619+
&::after {
620+
content: attr(data-text);
621+
}
618622
}
619623
}
620624

0 commit comments

Comments
 (0)