Need an interface to get coordinate from DOM.Node
Reported by
zhenjun....@gmail.com,
Apr 25 2018
|
|||||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 Steps to reproduce the problem: 1. Attach chrome.debugger in chrome extension 2. Get document by DOM.getDocument interface and locate one element with DOM.querySelector 3. DOM.querySelector will response one nodeID of the Dom tree 4. Need one way/interface to get the coordinate based on this nodeID, like the function in javascript: getBoundingClientRect(); What is the expected behavior? Expect one way to get more information of one Dom node. What went wrong? Cannot get coordinate of one node. Did this work before? N/A Chrome version: 65.0.3325.181 Channel: n/a OS Version: ubuntu 16.04 Flash Version:
,
Apr 26 2018
Thanks for filing the issue! @Reporter: Could you please share a sample test file/extension which helps us to triage the issue in a better way. Any further inputs from your end may be helpful.
,
Apr 26 2018
Thank you for providing more feedback. Adding the requester to the cc list. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Apr 26 2018
@vamshi.kommuri, thanks for your response.
Here are my codes calling DOM.getDocument in background.js:
var tab_id = 2;
chrome.debugger.attach({tabId: tab_id}, "1.3", onAttach.bind(null, tab_id));
chrome.debugger.sendCommand({tabId: tab_id}, 'Page.enable');
chrome.debugger.sendCommand({tabId: tab_id},
'DOM.getDocument', {"depth": -1, "pierce": true},
function(response) {
console.log('DOM.getDocument: ', response);
handleDOMTree(response.root);
});
With these codes in the extension, when you open one page in your browser, handleDOMTree callback function will be called.
In handleDOMTree, we can try to query DOM node by css selector, here is an example:
function handleDOMTree(n) {
var body = n;
for(var j = 0 ; j < n.childNodeCount; j ++){
if (n.children[j].localName == "body"){
// found body
body = n.children[j];
}
}
chrome.debugger.sendCommand({tabId: tab_id}, 'DOM.querySelector', {
"nodeId": body.nodeId,
"selector": ".tid-summary-navi-tab-header a" // replace it to an valid css selector on your page
}, function(response) {
var nodeId = response.nodeId;
console.log("Got node : ", response); // Need a way to get coordinate with nodeId here
});
}
,
May 2 2018
Any idea about it? I want to get coordinate based on a DOM.Node from debugger interface.
,
May 21 2018
Reporter@ - As per comment #4, please provide a sample test file/extension zip file to test the issue from TE-end. This will help us in triaging the issue further. Thanks...!!
,
May 21 2018
I think DOM.getBoxModel should work for you. Thanks for filing an issue!
,
Jun 5 2018
@dgozman, thanks, I can get the element rect and click it now. |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by krajshree@chromium.org
, Apr 25 2018