@rpascene/shared 0.30.13 → 0.30.15

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.
@@ -148,7 +148,8 @@ const YHT_STRING_ENV_KEYS = [
148
148
  'domain',
149
149
  'yht_access_token',
150
150
  'model',
151
- 'baseURL'
151
+ 'baseURL',
152
+ 'traceId'
152
153
  ];
153
154
  const YHT_NUMBER_ENV_KEYS = [
154
155
  'chatType',
@@ -30,7 +30,7 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
30
30
  rect.left += basePoint.left;
31
31
  rect.top += basePoint.top;
32
32
  }
33
- if (rect.height >= window.innerHeight && rect.width >= window.innerWidth) return null;
33
+ if (rect.height >= currentWindow.innerHeight && rect.width >= currentWindow.innerWidth) return null;
34
34
  if (isFormElement(node, currentWindow)) {
35
35
  const attributes = getNodeAttributes(node, currentWindow);
36
36
  let valueContent = attributes.value || attributes.placeholder || node.textContent || '';
@@ -65,6 +65,10 @@ function collectElementInfo(node, currentWindow, currentDocument, baseZoom = 1,
65
65
  if (isButtonElement(node, currentWindow)) {
66
66
  const rect = mergeElementAndChildrenRects(node, currentWindow, currentDocument, baseZoom);
67
67
  if (!rect) return null;
68
+ if (0 !== basePoint.left || 0 !== basePoint.top) {
69
+ rect.left += basePoint.left;
70
+ rect.top += basePoint.top;
71
+ }
68
72
  const attributes = getNodeAttributes(node, currentWindow);
69
73
  const pseudo = getPseudoElementContent(node, currentWindow);
70
74
  const content = node.innerText || pseudo.before || pseudo.after || '';
@@ -220,12 +224,9 @@ async function extractTreeNodeAsString(initNode, visibleOnly = false, debugMode
220
224
  async function extractTreeNode(initNode, debugMode = false, basePoint = {
221
225
  left: 0,
222
226
  top: 0
223
- }, baseZoom = 1, containerPaths = []) {
227
+ }, baseZoom = 1) {
224
228
  setDebugMode(debugMode);
225
229
  indexId = 0;
226
- let containerPathClone = [
227
- ...containerPaths
228
- ];
229
230
  const topDocument = getTopDocument();
230
231
  const startNode = initNode || topDocument;
231
232
  const topChildren = [];
@@ -236,11 +237,6 @@ async function extractTreeNode(initNode, debugMode = false, basePoint = {
236
237
  if (!node) return null;
237
238
  if (node.nodeType && 10 === node.nodeType) return null;
238
239
  const elementInfo = collectElementInfo(node, currentWindow, currentDocument, baseZoom, basePoint, false);
239
- if (elementInfo) {
240
- const allPaths = getLocators(node);
241
- elementInfo.allPaths = allPaths;
242
- elementInfo.containerPaths = containerPathClone;
243
- }
244
240
  if (node instanceof currentWindow.HTMLIFrameElement) {
245
241
  if (node.contentWindow && node.contentWindow) return null;
246
242
  }
@@ -285,18 +281,7 @@ async function extractTreeNode(initNode, debugMode = false, basePoint = {
285
281
  const iframe = iframes[i];
286
282
  const iframeInfo = collectElementInfo(iframe, window, document, 1);
287
283
  const baseZoom = getCssScale(iframe).cssScaleX;
288
- const containerPath = getContainerPath(iframe);
289
- containerPathClone = containerPathClone.concat(containerPath);
290
- if (iframeInfo) if (iframe.contentDocument && iframe.contentWindow) {
291
- console.log("iframe\u540C\u57DF");
292
- const iframeChildren = dfs(iframe.contentDocument.body, iframe.contentWindow, iframe.contentDocument, baseZoom, {
293
- left: iframeInfo.rect.left,
294
- top: iframeInfo.rect.top
295
- });
296
- if (Array.isArray(iframeChildren)) topChildren.push(...iframeChildren);
297
- else if (iframeChildren) topChildren.push(iframeChildren);
298
- } else {
299
- console.log(iframeInfo, "iframe\u8DE8\u57DF\u4E86");
284
+ if (iframeInfo) {
300
285
  const iframeChildren = await postWindowMessage(iframe.contentWindow, window, {
301
286
  action: 'extractTreeNode',
302
287
  data: {
@@ -304,8 +289,7 @@ async function extractTreeNode(initNode, debugMode = false, basePoint = {
304
289
  left: iframeInfo.rect.left,
305
290
  top: iframeInfo.rect.top
306
291
  },
307
- baseZoom,
308
- containerPaths: containerPathClone
292
+ baseZoom
309
293
  }
310
294
  });
311
295
  if (Array.isArray(iframeChildren)) topChildren.push(...iframeChildren);
@@ -351,7 +335,7 @@ function mergeElementAndChildrenRects(node, currentWindow, currentDocument, base
351
335
  }
352
336
  if ('undefined' != typeof window) onWindowMessage(window, async ({ action, data }, { source })=>{
353
337
  if ('extractTreeNode' === action) try {
354
- return await extractTreeNode(document.body, false, data.basePoint, data.baseZoom, data.containerPaths);
338
+ return await extractTreeNode(document.body, false, data.basePoint, data.baseZoom);
355
339
  } catch (error) {
356
340
  return {
357
341
  error: 'error message'