Trying a simple test to see whether I could get a similar behavior as the dev window provide when it highlights an element. This is not production code. I get this error:
{message: '{"code":-32600,"message":"Overlay must be enabled before a tool can be shown"}'} The error only occurs in the last command of the command stack.
So I added the command "Overlay.enable" to the stack of command, but I still get the same error.
I suppose in a production implementation, I'd have the tab id cached. I noted that getDocument always returns 1 for "result.root", so could I skip it (then proceed with the "querySelector" command.) But first I would want to not get the error.
My extension does highlight by adding to the DOM some zIndex'ed overlay and as someone as mentioned somewhere, it can affect the DOM, whereas the Debugger protocol highlight does not. It would make sense for my extension to use it.
Any pointer would be useful.
Here's the test code:
chrome.debugger.attach(
{ tabId:
tab.id },
'1.3', function () {
chrome.debugger.sendCommand(
{tabId:
tab.id},
"Overlay.enable",
{},
function (result) {
chrome.debugger.sendCommand(
{ tabId:
tab.id },
"DOM.getDocument",
{depth: -1},
function (result) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
} else {
chrome.debugger.sendCommand(
{ tabId:
tab.id },
"DOM.querySelector",
{
nodeId: result.root.nodeId,
selector: '[data-eid="collection-122836-dynamic_centerpiece_tab"]'
},
function (result) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
} else {
chrome.debugger.sendCommand(
{ tabId:
tab.id },
"DOM.highlightNode",
{
nodeId: result.nodeId,
highlightConfig: {
contentColor: {
r: 155,
g: 11,
b: 239,
a: 0.7
},
showInfo: true
}
},
function (result) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
}
}
);
}
}
);
}
}
);
}
);
}
);