From 3e5e9390975a5bc08ab2f51efa3461e26460ddfd Mon Sep 17 00:00:00 2001 From: Robbie Coomber Date: Mon, 25 Sep 2023 14:55:26 +0100 Subject: [PATCH] Add root $el_text --- playground/nextjs/pages/index.tsx | 4 ++++ src/__tests__/autocapture.js | 8 +++++--- src/autocapture.ts | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/playground/nextjs/pages/index.tsx b/playground/nextjs/pages/index.tsx index a9164fac5..72a23909b 100644 --- a/playground/nextjs/pages/index.tsx +++ b/playground/nextjs/pages/index.tsx @@ -35,6 +35,10 @@ export default function Home() {
+ + Autocapture a > span + + diff --git a/src/__tests__/autocapture.js b/src/__tests__/autocapture.js index 8c65d4a89..b8ef31643 100644 --- a/src/__tests__/autocapture.js +++ b/src/__tests__/autocapture.js @@ -886,10 +886,10 @@ describe('Autocapture system', () => { autocapture._captureEvent(e1, lib) const props1 = getCapturedProps(lib.capture) - expect(props1['$elements'][0]).toHaveProperty( - '$el_text', + const text1 = "Some super duper really long Text with new lines that we'll strip out and also we will want to make this text shorter since it's not likely people really care about text content that's super long and it also takes up more space and bandwidth. Some super d" - ) + expect(props1['$elements'][0]).toHaveProperty('$el_text', text1) + expect(props1['$el_text']).toEqual(text1) lib.capture.resetHistory() const e2 = { @@ -899,6 +899,7 @@ describe('Autocapture system', () => { autocapture._captureEvent(e2, lib) const props2 = getCapturedProps(lib.capture) expect(props2['$elements'][0]).toHaveProperty('$el_text', 'Some text') + expect(props2['$el_text']).toEqual('Some text') lib.capture.resetHistory() const e3 = { @@ -908,6 +909,7 @@ describe('Autocapture system', () => { autocapture._captureEvent(e3, lib) const props3 = getCapturedProps(lib.capture) expect(props3['$elements'][0]).toHaveProperty('$el_text', '') + expect(props3).not.toHaveProperty('$el_text') }) it('does not capture sensitive text content', () => { diff --git a/src/autocapture.ts b/src/autocapture.ts index 0e3749ed9..5913d7070 100644 --- a/src/autocapture.ts +++ b/src/autocapture.ts @@ -265,6 +265,7 @@ const autocapture = { { $elements: elementsJson, }, + elementsJson[0]?.['$el_text'] ? { $el_text: elementsJson[0]?.['$el_text'] } : {}, this._getCustomProperties(targetElementList), autocaptureAugmentProperties )