The text format is hard-coded as the concatenation of the node name, ID and class names. Changing any of these values will change the displayed tooltip. For example, setting the class name using element.className = 'Hello\xA0world!';
results in a tooltip containing Hello world!
(note: I'm using the non-breaking space \xA0
because normal spaces are replaced with dots in the title).
The previous method doesn't offer much flexibility in positioning or coloring of your custom text. A way to gain much more control over the displayed text is by editing the devtools' source code in resources.pak
. This process is explained in detail in this answer (read it before continuing).
The displayed text is part of an overlay that is rendered by InspectorOverlayPage.html. Edit resources.pak
, search for that line (e.g. by searching for id="element-title"
) and modify it (make sure that the number of bytes does not change, e.g. by renaming tags, removing quotes and/or collapsing superfluous whitespace). For example:
OLD: <span id="node-width"></span><span class="px">px</span><span class="px"> × </span><span id="node-height"></span><span class="px">px</span>
NEW: <a id=node-width></a><a class=px>px</a><a class=px> × </a><a id=node-height></a><a class=px>px</a><a style="color:red;">My custom text</a>

Changing colors only
If you just want to change the colors, then you can also solve the issue by changing the (hard-coded) color configuration in resources.pak
.
The highlight colors are defined at WebInspector.Color.PageHighlight
in Source/devtools/front_end/common/Color.js. This resource is minified and included in resources.pak
, so if you open resources.pak
with a hex editor and look for WebInspector.Color.PageHighlight=
, then you will find a way to change the default color values (note: when I just tried this method, I found two occurrences of this string, I had to modify the second occurrence to get the desired effect.
For example, to change the color of the box's content, I modified the Content
color definition. Inside resources.pak
, there is a long line containing WebInspector.Color.PageHighlight={Content:WebInspector.Color.fromRGBA([111,168,220,.66]),
.
After changing it to WebInspector.Color.PageHighlight={Content:WebInspector.Color.fromRGBA([255, 0,0 ,.66]),
(note: the number of characters must match, pad it with spaces if needed), the default box will be red:

Alternatives
Instead of modifying resources.pak
, you could also create an extension that runs in the content of the developer tools that changes the color, e.g. by calling WebInspector.Color.PageHighlight.Content = WebInspector.Color.fromRGBA([255, 0,0,.66]);
.
Or, if you don't want to integrate with the devtools at all, you could create an extension that uses the chrome.debugger
API and the devtools protocol to highlight a node using the DOM.highlightNode
command.
Another option is to open a feature request at https://crbug.com/new and ask for an option to change the colors. A similar feature request was shot down, so this option won't work for your current case.