Skip to content

Commit acf9d77

Browse files
authored
🐛 Fix Shopify Custom Pixel actions being marked as background events, flatten ui_extension_errored context (#4946)
1 parent 0b06411 commit acf9d77

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

packages/browser-rum-shopify/src/boot/patchSandboxedIframeApis.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import { globalObject } from '@datadog/browser-core'
1111
* denied without Permissions Policy delegation), but the SDK only catches an async rejection.
1212
* - `getPristineWindow()` creates a nested iframe to read an unpatched `URL` constructor; that
1313
* nested iframe's `contentWindow` is cross-origin here, and reading a property off it throws.
14+
* - `document.hasFocus()` always returns `false`: the pixel iframe has no focusable UI, so it can
15+
* never hold browser focus regardless of whether the customer is actively looking at the page.
1416
* Shimming these away makes the SDK fall back to code paths that do work in this context
15-
* (`document.cookie`, same-document promise chaining, `globalObject.URL`).
17+
* (`document.cookie`, same-document promise chaining, `globalObject.URL`, always-focused state).
1618
*/
1719
export function patchSandboxedIframeApis() {
1820
disableProperty(globalObject, 'cookieStore')
@@ -24,6 +26,12 @@ export function patchSandboxedIframeApis() {
2426
},
2527
configurable: true,
2628
})
29+
30+
Object.defineProperty(document, 'hasFocus', {
31+
value: () => true,
32+
configurable: true,
33+
writable: true,
34+
})
2735
}
2836

2937
function disableProperty(target: object, key: string) {

packages/browser-rum-shopify/src/domain/shopifyBindings.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('initShopifyBindings', () => {
122122
expect(stopAction).toHaveBeenCalledWith('element-without-id', { type: 'click' })
123123
})
124124

125-
it('maps "ui_extension_errored" to addError with the extension context', () => {
125+
it('maps "ui_extension_errored" to addError with the flattened extension context', () => {
126126
const { rumPublicApi, addError } = createFakeRumPublicApi()
127127
const { analytics, emit } = createFakeAnalytics()
128128

@@ -138,18 +138,20 @@ describe('initShopifyBindings', () => {
138138
extensionName: 'my-extension',
139139
extensionTarget: 'purchase.checkout.block.render',
140140
type: 'RUNTIME',
141+
appId: 'gid://shopify/App/1',
141142
appName: 'my-app',
143+
appVersion: '1.2.3',
142144
},
143145
},
144146
})
145147

146148
expect(addError).toHaveBeenCalledWith(jasmine.objectContaining({ message: 'Boom', stack: 'stack trace' }), {
147-
extension: {
148-
name: 'my-extension',
149-
target: 'purchase.checkout.block.render',
150-
type: 'RUNTIME',
151-
appName: 'my-app',
152-
},
149+
extensionName: 'my-extension',
150+
extensionTarget: 'purchase.checkout.block.render',
151+
extensionErrorType: 'RUNTIME',
152+
appId: 'gid://shopify/App/1',
153+
appName: 'my-app',
154+
appVersion: '1.2.3',
153155
})
154156
})
155157
})

packages/browser-rum-shopify/src/domain/shopifyBindings.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export interface ErrorData {
1111
extensionName?: string
1212
extensionTarget?: string
1313
type?: string
14+
appId?: string
1415
appName?: string
16+
appVersion?: string
1517
}
1618

1719
// Matches /checkouts/*, /checkout, including locale-prefixed paths.
@@ -54,12 +56,12 @@ export function initShopifyBindings(rumPublicApi: RumPublicApi, analytics: Shopi
5456
const err = new Error(error?.message)
5557
err.stack = error?.trace
5658
rumPublicApi.addError(err, {
57-
extension: {
58-
name: error?.extensionName,
59-
target: error?.extensionTarget,
60-
type: error?.type,
61-
appName: error?.appName,
62-
},
59+
extensionName: error?.extensionName,
60+
extensionTarget: error?.extensionTarget,
61+
extensionErrorType: error?.type,
62+
appId: error?.appId,
63+
appName: error?.appName,
64+
appVersion: error?.appVersion,
6365
})
6466
})
6567
}

0 commit comments

Comments
 (0)