@@ -45,6 +45,67 @@ test.describe('Outbound domains tracking', () => {
4545 expect ( iframeSrc ) . toContain ( 'dub_id=test-click-id' ) ;
4646 } ) ;
4747
48+ test ( 'should handle nested iframes inside srcdoc (Cal.com style)' , async ( {
49+ page,
50+ } ) => {
51+ await page . goto ( '/outbound?dub_id=test-click-id' ) ;
52+
53+ await page . waitForFunction ( ( ) => window . _dubAnalytics !== undefined ) ;
54+
55+ await page . waitForTimeout ( 2500 ) ;
56+
57+ // Check that nested iframes inside srcdoc get tracking parameters
58+ // This tests the contentDocument access functionality
59+ const nestedIframeCheck = await page . evaluate ( ( ) => {
60+ const srcdocIframes = document . querySelectorAll ( 'iframe[srcdoc]' ) ;
61+ const results = [ ] ;
62+
63+ srcdocIframes . forEach ( ( srcdocIframe , index ) => {
64+ try {
65+ const contentDoc = srcdocIframe . contentDocument ;
66+ if ( contentDoc ) {
67+ const nestedIframes = contentDoc . querySelectorAll ( 'iframe[src]' ) ;
68+ nestedIframes . forEach ( ( nestedIframe ) => {
69+ results . push ( {
70+ index,
71+ src : nestedIframe . src ,
72+ hasTracking : nestedIframe . src . includes ( 'dub_id=test-click-id' ) ,
73+ } ) ;
74+ } ) ;
75+ }
76+ } catch ( e ) {
77+ results . push ( { index, error : e . message } ) ;
78+ }
79+ } ) ;
80+
81+ return results ;
82+ } ) ;
83+
84+ // Verify that nested iframes were found and have tracking parameters
85+ expect ( nestedIframeCheck . length ) . toBeGreaterThan ( 0 ) ;
86+
87+ // Check that at least some nested iframes have tracking
88+ const trackedIframes = nestedIframeCheck . filter (
89+ ( result ) => result . hasTracking ,
90+ ) ;
91+ expect ( trackedIframes . length ) . toBeGreaterThan ( 0 ) ;
92+
93+ // Verify specific URLs got tracking
94+ const exampleTracked = nestedIframeCheck . some (
95+ ( result ) =>
96+ result . src &&
97+ result . src . includes ( 'example.com/booking-widget?dub_id=test-click-id' ) ,
98+ ) ;
99+ const otherTracked = nestedIframeCheck . some (
100+ ( result ) =>
101+ result . src &&
102+ result . src . includes ( 'other.com/calendar?dub_id=test-click-id' ) ,
103+ ) ;
104+
105+ expect ( exampleTracked ) . toBe ( true ) ;
106+ expect ( otherTracked ) . toBe ( true ) ;
107+ } ) ;
108+
48109 test ( 'should not add tracking to links on the same domain' , async ( {
49110 page,
50111 } ) => {
0 commit comments