This is a follow-up from Bug 1572651.
There are scenarios where the inferred
selectedBrowser where the box model renderer will draw is not the correct one. This can happen in a few cases as explained by Julian in code review:
If you start using devtools in a separate window, or worse, remote debugging, it's possible to make this assumption fail.
An "easy" one with DevTools docked as a separate window.
First of all, to setup devtools correctly
open devtools wherever
detach them to a separate window
select the console (or any tool except the inspector really)
open two browser windows, window A on google.com, window B on mozilla.org
open devtools on window A (it should open in a separate window, with webconsole selected)
click in window B
select inspector in devtools
-> Highlighter will be created in window B but will highlight elements from window A.
Maybe a fix will be to let the observer pass the browsingContext id to the highlighter so that it can find the right element?
debugging a local extension via about:debugging will also confuse this. When the about:devtools-toolbox loads, the selectedBrowser will be the one for the about:devtools-toolbox tab and not the one for the addon.