@midscene/recorder-ui 1.17.2 → 1.17.3-beta-20261029072240.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,6 +59,46 @@
59
59
  }
60
60
  return false;
61
61
  }
62
+ function getContainingShadowRoot(node) {
63
+ const root = node.getRootNode?.();
64
+ return root && 'host' in root ? root : null;
65
+ }
66
+ const shadow_locator_shadowLocatorPrefix = 'midscene-shadow-v1:';
67
+ const normalizeText = (text)=>text.replace(/\s+/g, ' ').trim();
68
+ function buildShadowLocator(node, root, host, orderSensitive, leaf) {
69
+ const textNode = 3 === node.nodeType;
70
+ const element = textNode ? node.parentElement : node;
71
+ if (!element) throw new Error('Cannot cache a detached shadow text node');
72
+ const steps = [];
73
+ for(let current = element; current; current = current.parentElement){
74
+ const parent = current.parentNode;
75
+ if (!parent) throw new Error('Cannot cache a detached shadow element');
76
+ const tag = current.localName;
77
+ const namespace = current.namespaceURI;
78
+ const siblings = Array.from(parent.children).filter((sibling)=>sibling.localName === tag && sibling.namespaceURI === namespace);
79
+ const text = normalizeText(current.textContent || '');
80
+ steps.unshift({
81
+ tag,
82
+ namespace,
83
+ match: !orderSensitive && (leaf || textNode) && current === element && text ? {
84
+ kind: 'text',
85
+ value: text
86
+ } : {
87
+ kind: 'index',
88
+ value: siblings.indexOf(current)
89
+ }
90
+ });
91
+ if (parent === root) {
92
+ const locator = {
93
+ host,
94
+ steps,
95
+ text: textNode ? normalizeText(node.textContent || '') : null
96
+ };
97
+ return shadow_locator_shadowLocatorPrefix + encodeURIComponent(JSON.stringify(locator));
98
+ }
99
+ }
100
+ throw new Error('Shadow target does not belong to the supplied root');
101
+ }
62
102
  let debugMode = false;
63
103
  function util_logger(..._msg) {
64
104
  if (!debugMode) return;
@@ -94,6 +134,8 @@
94
134
  return `${prefix}${tagSelector}[${index}]`;
95
135
  };
96
136
  const getElementXpath = (element, isOrderSensitive = false, isLeafElement = false, limitToCurrentDocument = false)=>{
137
+ const shadowRoot = getContainingShadowRoot(element);
138
+ if (shadowRoot) return buildShadowLocator(element, shadowRoot, getElementXpath(shadowRoot.host, isOrderSensitive, false, limitToCurrentDocument), isOrderSensitive, isLeafElement);
97
139
  if (element.nodeType === Node.TEXT_NODE) {
98
140
  const parentNode = element.parentNode;
99
141
  if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/recorder-ui",
3
- "version": "1.17.2",
3
+ "version": "1.17.3-beta-20261029072240.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/midscene.git",
@@ -29,7 +29,7 @@
29
29
  "antd": "^5.21.6",
30
30
  "dayjs": "^1.11.11",
31
31
  "react-dom": "18.3.1",
32
- "@midscene/shared": "1.17.2"
32
+ "@midscene/shared": "1.17.3-beta-20261029072240.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "18.3.1",