From a81ccc0efac09b8bca28c66f4f3a1471dc206557 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Wed, 21 May 2025 15:48:19 +0900 Subject: [PATCH] Improve `getElementPosition()` for handling elements within a shadow root --- lib/chrome.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/chrome.js b/lib/chrome.js index bf28f17..baeebc2 100644 --- a/lib/chrome.js +++ b/lib/chrome.js @@ -759,6 +759,31 @@ var ChromeObject = function() { } }; + this.getDeepElementPosition = function(selectors) { + var result = this.getEvaluatedValue('(function() { var rect = __getDocument().' + this.getShadowRootSelector(selectors) + '.getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })();'); + var pos = result.split(','); + + if (pos.length == 6) { + return { + "x": parseInt(pos[0]), + "y": parseInt(pos[1]), + "a": parseInt(pos[2]), + "b": parseInt(pos[3]), + "w": parseInt(pos[4]), + "h": parseInt(pos[5]) + }; + } else { + return { + "x": -1, + "y": -1, + "a": -1, + "b": -1, + "g": -1, + "d": -1 + }; + } + }; + this.getElementPositionByText = function(selector, searchText) { var result; var pos = -1; @@ -1423,7 +1448,7 @@ exports.startDebugInPrivate = function(url, proxy, profileName, debuggingPort, i ; }; -exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.15"; +exports.VERSIONINFO = "Chrome Web Browser Debugging Interface (chrome.js) version 0.4.16"; exports.AUTHOR = "abuse@catswords.net"; exports.global = global; exports.require = global.require;