@datadog/browser-rum-shopify 7.8.0 → 7.10.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.
@@ -1,15 +1 @@
1
- /**
2
- * A Shopify Custom Pixel runs in a "lax" sandboxed iframe (`sandbox="allow-scripts"`, no
3
- * `allow-same-origin`): it shares the parent page's cookie jar (same domain) but has an
4
- * opaque/`null` origin for its own window/document. Several browser APIs the RUM SDK relies on
5
- * either don't work there or throw synchronously in ways the SDK doesn't fully guard against,
6
- * which silently breaks session tracking and view/URL resolution:
7
- * - `cookieStore.getAll()` is blocked; `document.cookie` works fine as a fallback.
8
- * - `navigator.locks.request()` throws a synchronous `SecurityError` (the Web Locks API is
9
- * denied without Permissions Policy delegation), but the SDK only catches an async rejection.
10
- * - `getPristineWindow()` creates a nested iframe to read an unpatched `URL` constructor; that
11
- * nested iframe's `contentWindow` is cross-origin here, and reading a property off it throws.
12
- * Shimming these away makes the SDK fall back to code paths that do work in this context
13
- * (`document.cookie`, same-document promise chaining, `globalObject.URL`).
14
- */
15
1
  export declare function patchSandboxedIframeApis(): void;
@@ -1,4 +1,4 @@
1
- let _datadog_browser_core = require("@datadog/browser-core");
1
+ let _datadog_js_core_util = require("@datadog/js-core/util");
2
2
  //#region src/boot/patchSandboxedIframeApis.ts
3
3
  /**
4
4
  * A Shopify Custom Pixel runs in a "lax" sandboxed iframe (`sandbox="allow-scripts"`, no
@@ -9,19 +9,18 @@ let _datadog_browser_core = require("@datadog/browser-core");
9
9
  * - `cookieStore.getAll()` is blocked; `document.cookie` works fine as a fallback.
10
10
  * - `navigator.locks.request()` throws a synchronous `SecurityError` (the Web Locks API is
11
11
  * denied without Permissions Policy delegation), but the SDK only catches an async rejection.
12
- * - `getPristineWindow()` creates a nested iframe to read an unpatched `URL` constructor; that
13
- * nested iframe's `contentWindow` is cross-origin here, and reading a property off it throws.
12
+ * - `document.hasFocus()` always returns `false`: the pixel iframe has no focusable UI, so it can
13
+ * never hold browser focus regardless of whether the customer is actively looking at the page.
14
14
  * 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`).
15
+ * (`document.cookie`, same-document promise chaining, `globalObject.URL`, always-focused state).
16
16
  */
17
17
  function patchSandboxedIframeApis() {
18
- disableProperty(_datadog_browser_core.globalObject, "cookieStore");
18
+ disableProperty(_datadog_js_core_util.globalObject, "cookieStore");
19
19
  disableProperty(navigator, "locks");
20
- Object.defineProperty(HTMLIFrameElement.prototype, "contentWindow", {
21
- get() {
22
- return null;
23
- },
24
- configurable: true
20
+ Object.defineProperty(document, "hasFocus", {
21
+ value: () => true,
22
+ configurable: true,
23
+ writable: true
25
24
  });
26
25
  }
27
26
  function disableProperty(target, key) {
@@ -1 +1 @@
1
- {"version":3,"file":"patchSandboxedIframeApis.js","names":["globalObject"],"sources":["../../src/boot/patchSandboxedIframeApis.ts"],"sourcesContent":["import { globalObject } from '@datadog/browser-core'\n\n/**\n * A Shopify Custom Pixel runs in a \"lax\" sandboxed iframe (`sandbox=\"allow-scripts\"`, no\n * `allow-same-origin`): it shares the parent page's cookie jar (same domain) but has an\n * opaque/`null` origin for its own window/document. Several browser APIs the RUM SDK relies on\n * either don't work there or throw synchronously in ways the SDK doesn't fully guard against,\n * which silently breaks session tracking and view/URL resolution:\n * - `cookieStore.getAll()` is blocked; `document.cookie` works fine as a fallback.\n * - `navigator.locks.request()` throws a synchronous `SecurityError` (the Web Locks API is\n * denied without Permissions Policy delegation), but the SDK only catches an async rejection.\n * - `getPristineWindow()` creates a nested iframe to read an unpatched `URL` constructor; that\n * nested iframe's `contentWindow` is cross-origin here, and reading a property off it throws.\n * Shimming these away makes the SDK fall back to code paths that do work in this context\n * (`document.cookie`, same-document promise chaining, `globalObject.URL`).\n */\nexport function patchSandboxedIframeApis() {\n disableProperty(globalObject, 'cookieStore')\n disableProperty(navigator, 'locks')\n\n Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {\n get() {\n return null\n },\n configurable: true,\n })\n}\n\nfunction disableProperty(target: object, key: string) {\n Object.defineProperty(target, key, {\n value: undefined,\n configurable: true,\n writable: true,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,2BAA2B;CACzC,gBAAgBA,sBAAAA,cAAc,aAAa;CAC3C,gBAAgB,WAAW,OAAO;CAElC,OAAO,eAAe,kBAAkB,WAAW,iBAAiB;EAClE,MAAM;GACJ,OAAO;EACT;EACA,cAAc;CAChB,CAAC;AACH;AAEA,SAAS,gBAAgB,QAAgB,KAAa;CACpD,OAAO,eAAe,QAAQ,KAAK;EACjC,OAAO,KAAA;EACP,cAAc;EACd,UAAU;CACZ,CAAC;AACH"}
1
+ {"version":3,"file":"patchSandboxedIframeApis.js","names":["globalObject"],"sources":["../../src/boot/patchSandboxedIframeApis.ts"],"sourcesContent":["/**\n * A Shopify Custom Pixel runs in a \"lax\" sandboxed iframe (`sandbox=\"allow-scripts\"`, no\n * `allow-same-origin`): it shares the parent page's cookie jar (same domain) but has an\n * opaque/`null` origin for its own window/document. Several browser APIs the RUM SDK relies on\n * either don't work there or throw synchronously in ways the SDK doesn't fully guard against,\n * which silently breaks session tracking and view/URL resolution:\n * - `cookieStore.getAll()` is blocked; `document.cookie` works fine as a fallback.\n * - `navigator.locks.request()` throws a synchronous `SecurityError` (the Web Locks API is\n * denied without Permissions Policy delegation), but the SDK only catches an async rejection.\n * - `document.hasFocus()` always returns `false`: the pixel iframe has no focusable UI, so it can\n * never hold browser focus regardless of whether the customer is actively looking at the page.\n * Shimming these away makes the SDK fall back to code paths that do work in this context\n * (`document.cookie`, same-document promise chaining, `globalObject.URL`, always-focused state).\n */\nimport { globalObject } from '@datadog/js-core/util'\nexport function patchSandboxedIframeApis() {\n disableProperty(globalObject, 'cookieStore')\n disableProperty(navigator, 'locks')\n\n Object.defineProperty(document, 'hasFocus', {\n value: () => true,\n configurable: true,\n writable: true,\n })\n}\n\nfunction disableProperty(target: object, key: string) {\n Object.defineProperty(target, key, {\n value: undefined,\n configurable: true,\n writable: true,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,2BAA2B;CACzC,gBAAgBA,sBAAAA,cAAc,aAAa;CAC3C,gBAAgB,WAAW,OAAO;CAElC,OAAO,eAAe,UAAU,YAAY;EAC1C,aAAa;EACb,cAAc;EACd,UAAU;CACZ,CAAC;AACH;AAEA,SAAS,gBAAgB,QAAgB,KAAa;CACpD,OAAO,eAAe,QAAQ,KAAK;EACjC,OAAO,KAAA;EACP,cAAc;EACd,UAAU;CACZ,CAAC;AACH"}
@@ -9,7 +9,9 @@ export interface ErrorData {
9
9
  extensionName?: string;
10
10
  extensionTarget?: string;
11
11
  type?: string;
12
+ appId?: string;
12
13
  appName?: string;
14
+ appVersion?: string;
13
15
  }
14
16
  /**
15
17
  * Wires Shopify Web Pixel standard events to the RUM public API. `analytics` is the sandbox's
@@ -20,12 +20,14 @@ function initShopifyBindings(rumPublicApi, analytics) {
20
20
  const error = event.data?.error;
21
21
  const err = new Error(error?.message);
22
22
  err.stack = error?.trace;
23
- rumPublicApi.addError(err, { extension: {
24
- name: error?.extensionName,
25
- target: error?.extensionTarget,
26
- type: error?.type,
27
- appName: error?.appName
28
- } });
23
+ rumPublicApi.addError(err, {
24
+ extensionName: error?.extensionName,
25
+ extensionTarget: error?.extensionTarget,
26
+ extensionErrorType: error?.type,
27
+ appId: error?.appId,
28
+ appName: error?.appName,
29
+ appVersion: error?.appVersion
30
+ });
29
31
  });
30
32
  }
31
33
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"shopifyBindings.js","names":[],"sources":["../../src/domain/shopifyBindings.ts"],"sourcesContent":["import type { RumPublicApi } from '@datadog/browser-rum-core'\nimport type { ShopifyAnalyticsApi, ShopifyPixelEvent } from './shopifyAnalytics'\n\nexport interface ElementData {\n id?: string\n}\n\nexport interface ErrorData {\n message?: string\n trace?: string\n extensionName?: string\n extensionTarget?: string\n type?: string\n appName?: string\n}\n\n// Matches /checkouts/*, /checkout, including locale-prefixed paths.\n// Storefront pages never match, so init() is a no-op there: those pages\n// already get a `DD_RUM` instance from the Theme Liquid snippet, and initializing here too would\n// create a second, independent SDK instance double-tracking the same page view.\nconst CHECKOUT_PATH = /\\/(([a-z]{2}(-[a-z0-9]+)?)\\/)?(checkouts?)(\\/|$)/i\n\n/**\n * Wires Shopify Web Pixel standard events to the RUM public API. `analytics` is the sandbox's\n * `analytics` global (or `undefined` outside the sandbox, in which case bindings are skipped).\n */\nexport function initShopifyBindings(rumPublicApi: RumPublicApi, analytics: ShopifyAnalyticsApi | undefined) {\n if (!analytics) {\n return\n }\n\n analytics.subscribe('page_viewed', (event) => {\n const url = event.context?.document?.location?.href\n\n if (!url || !CHECKOUT_PATH.test(url)) {\n return\n }\n\n rumPublicApi.startView({\n url,\n })\n })\n\n analytics.subscribe('clicked', (event: ShopifyPixelEvent<{ element?: ElementData }>) => {\n const element = event.data?.element\n const name = element?.id ?? 'element-without-id'\n rumPublicApi.startAction(name, { type: 'click' })\n rumPublicApi.stopAction(name, { type: 'click' })\n })\n\n // Fires when a Shopify checkout UI extension crashes.\n analytics.subscribe('ui_extension_errored', (event: ShopifyPixelEvent<{ error?: ErrorData }>) => {\n const error = event.data?.error\n const err = new Error(error?.message)\n err.stack = error?.trace\n rumPublicApi.addError(err, {\n extension: {\n name: error?.extensionName,\n target: error?.extensionTarget,\n type: error?.type,\n appName: error?.appName,\n },\n })\n })\n}\n"],"mappings":";AAoBA,MAAM,gBAAgB;;;;;AAMtB,SAAgB,oBAAoB,cAA4B,WAA4C;CAC1G,IAAI,CAAC,WACH;CAGF,UAAU,UAAU,gBAAgB,UAAU;EAC5C,MAAM,MAAM,MAAM,SAAS,UAAU,UAAU;EAE/C,IAAI,CAAC,OAAO,CAAC,cAAc,KAAK,GAAG,GACjC;EAGF,aAAa,UAAU,EACrB,IACF,CAAC;CACH,CAAC;CAED,UAAU,UAAU,YAAY,UAAwD;EAEtF,MAAM,QADU,MAAM,MAAM,QAAA,EACN,MAAM;EAC5B,aAAa,YAAY,MAAM,EAAE,MAAM,QAAQ,CAAC;EAChD,aAAa,WAAW,MAAM,EAAE,MAAM,QAAQ,CAAC;CACjD,CAAC;CAGD,UAAU,UAAU,yBAAyB,UAAoD;EAC/F,MAAM,QAAQ,MAAM,MAAM;EAC1B,MAAM,MAAM,IAAI,MAAM,OAAO,OAAO;EACpC,IAAI,QAAQ,OAAO;EACnB,aAAa,SAAS,KAAK,EACzB,WAAW;GACT,MAAM,OAAO;GACb,QAAQ,OAAO;GACf,MAAM,OAAO;GACb,SAAS,OAAO;EAClB,EACF,CAAC;CACH,CAAC;AACH"}
1
+ {"version":3,"file":"shopifyBindings.js","names":[],"sources":["../../src/domain/shopifyBindings.ts"],"sourcesContent":["import type { RumPublicApi } from '@datadog/browser-rum-core'\nimport type { ShopifyAnalyticsApi, ShopifyPixelEvent } from './shopifyAnalytics'\n\nexport interface ElementData {\n id?: string\n}\n\nexport interface ErrorData {\n message?: string\n trace?: string\n extensionName?: string\n extensionTarget?: string\n type?: string\n appId?: string\n appName?: string\n appVersion?: string\n}\n\n// Matches /checkouts/*, /checkout, including locale-prefixed paths.\n// Storefront pages never match, so init() is a no-op there: those pages\n// already get a `DD_RUM` instance from the Theme Liquid snippet, and initializing here too would\n// create a second, independent SDK instance double-tracking the same page view.\nconst CHECKOUT_PATH = /\\/(([a-z]{2}(-[a-z0-9]+)?)\\/)?(checkouts?)(\\/|$)/i\n\n/**\n * Wires Shopify Web Pixel standard events to the RUM public API. `analytics` is the sandbox's\n * `analytics` global (or `undefined` outside the sandbox, in which case bindings are skipped).\n */\nexport function initShopifyBindings(rumPublicApi: RumPublicApi, analytics: ShopifyAnalyticsApi | undefined) {\n if (!analytics) {\n return\n }\n\n analytics.subscribe('page_viewed', (event) => {\n const url = event.context?.document?.location?.href\n\n if (!url || !CHECKOUT_PATH.test(url)) {\n return\n }\n\n rumPublicApi.startView({\n url,\n })\n })\n\n analytics.subscribe('clicked', (event: ShopifyPixelEvent<{ element?: ElementData }>) => {\n const element = event.data?.element\n const name = element?.id ?? 'element-without-id'\n rumPublicApi.startAction(name, { type: 'click' })\n rumPublicApi.stopAction(name, { type: 'click' })\n })\n\n // Fires when a Shopify checkout UI extension crashes.\n analytics.subscribe('ui_extension_errored', (event: ShopifyPixelEvent<{ error?: ErrorData }>) => {\n const error = event.data?.error\n const err = new Error(error?.message)\n err.stack = error?.trace\n rumPublicApi.addError(err, {\n extensionName: error?.extensionName,\n extensionTarget: error?.extensionTarget,\n extensionErrorType: error?.type,\n appId: error?.appId,\n appName: error?.appName,\n appVersion: error?.appVersion,\n })\n })\n}\n"],"mappings":";AAsBA,MAAM,gBAAgB;;;;;AAMtB,SAAgB,oBAAoB,cAA4B,WAA4C;CAC1G,IAAI,CAAC,WACH;CAGF,UAAU,UAAU,gBAAgB,UAAU;EAC5C,MAAM,MAAM,MAAM,SAAS,UAAU,UAAU;EAE/C,IAAI,CAAC,OAAO,CAAC,cAAc,KAAK,GAAG,GACjC;EAGF,aAAa,UAAU,EACrB,IACF,CAAC;CACH,CAAC;CAED,UAAU,UAAU,YAAY,UAAwD;EAEtF,MAAM,QADU,MAAM,MAAM,QAAA,EACN,MAAM;EAC5B,aAAa,YAAY,MAAM,EAAE,MAAM,QAAQ,CAAC;EAChD,aAAa,WAAW,MAAM,EAAE,MAAM,QAAQ,CAAC;CACjD,CAAC;CAGD,UAAU,UAAU,yBAAyB,UAAoD;EAC/F,MAAM,QAAQ,MAAM,MAAM;EAC1B,MAAM,MAAM,IAAI,MAAM,OAAO,OAAO;EACpC,IAAI,QAAQ,OAAO;EACnB,aAAa,SAAS,KAAK;GACzB,eAAe,OAAO;GACtB,iBAAiB,OAAO;GACxB,oBAAoB,OAAO;GAC3B,OAAO,OAAO;GACd,SAAS,OAAO;GAChB,YAAY,OAAO;EACrB,CAAC;CACH,CAAC;AACH"}
@@ -1,9 +1,12 @@
1
1
  const require_makeShopifyRumPublicApi = require("../boot/makeShopifyRumPublicApi.js");
2
+ let _datadog_js_core_util = require("@datadog/js-core/util");
2
3
  let _datadog_browser_core = require("@datadog/browser-core");
3
4
  let _datadog_browser_rum_core = require("@datadog/browser-rum-core");
4
5
  let _datadog_browser_rum_internal = require("@datadog/browser-rum/internal");
5
6
  //#region src/entries/main.ts
6
- (0, _datadog_browser_core.defineGlobal)(_datadog_browser_core.globalObject, "DD_RUM", require_makeShopifyRumPublicApi.makeShopifyRumPublicApi((0, _datadog_browser_rum_core.makeRumPublicApi)((0, _datadog_browser_rum_internal.makeRecorderApi)(), (0, _datadog_browser_rum_internal.makeProfilerApi)(), { sdkName: "rum-shopify" })));
7
+ const global = _datadog_js_core_util.globalObject;
8
+ const datadogRum = require_makeShopifyRumPublicApi.makeShopifyRumPublicApi((0, _datadog_browser_rum_core.makeRumPublicApi)((0, _datadog_browser_rum_internal.makeRecorderApi)(), (0, _datadog_browser_rum_internal.makeProfilerApi)(), { sdkName: "rum-shopify" }));
9
+ (0, _datadog_browser_core.defineGlobal)(global, "DD_RUM", datadogRum);
7
10
  //#endregion
8
11
 
9
12
  //# sourceMappingURL=main.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","names":["global","makeShopifyRumPublicApi"],"sources":["../../src/entries/main.ts"],"sourcesContent":["import { defineGlobal, globalObject } from '@datadog/browser-core'\nimport type { RumPublicApi } from '@datadog/browser-rum-core'\nimport { makeRumPublicApi } from '@datadog/browser-rum-core'\nimport { makeRecorderApi, makeProfilerApi } from '@datadog/browser-rum/internal'\nimport { makeShopifyRumPublicApi } from '../boot/makeShopifyRumPublicApi'\n\ninterface BrowserWindow {\n DD_RUM?: RumPublicApi\n}\n\nconst global = globalObject as BrowserWindow\n\nconst datadogRum = makeShopifyRumPublicApi(\n makeRumPublicApi(makeRecorderApi(), makeProfilerApi(), {\n sdkName: 'rum-shopify',\n })\n)\n\ndefineGlobal(global, 'DD_RUM', datadogRum)\n"],"mappings":";;;;;CAkBaA,GAAAA,sBAAAA,aAAAA,CAAAA,sBAAAA,cAAQ,UANFC,gCAAAA,yBAAAA,GAAAA,0BAAAA,iBAAAA,EAAAA,GAAAA,8BAAAA,gBAAAA,CACgB,IAAA,GAAA,8BAAA,gBAAA,CAAmB,GAAG,EACrD,SAAS,cACX,CAAC,CAGqC,CAAC"}
1
+ {"version":3,"file":"main.js","names":["globalObject","makeShopifyRumPublicApi","makeRumPublicApi","makeRecorderApi","makeProfilerApi","defineGlobal"],"sources":["../../src/entries/main.ts"],"sourcesContent":["import { globalObject } from '@datadog/js-core/util'\nimport { defineGlobal } from '@datadog/browser-core'\nimport type { RumPublicApi } from '@datadog/browser-rum-core'\nimport { makeRumPublicApi } from '@datadog/browser-rum-core'\nimport { makeRecorderApi, makeProfilerApi } from '@datadog/browser-rum/internal'\nimport { makeShopifyRumPublicApi } from '../boot/makeShopifyRumPublicApi'\n\ninterface BrowserWindow {\n DD_RUM?: RumPublicApi\n}\n\nconst global = globalObject as BrowserWindow\n\nconst datadogRum = makeShopifyRumPublicApi(\n makeRumPublicApi(makeRecorderApi(), makeProfilerApi(), {\n sdkName: 'rum-shopify',\n })\n)\n\ndefineGlobal(global, 'DD_RUM', datadogRum)\n"],"mappings":";;;;;;AAWA,MAAM,SAASA,sBAAAA;AAEf,MAAM,aAAaC,gCAAAA,yBAAAA,GACjBC,0BAAAA,iBAAAA,EAAAA,GAAiBC,8BAAAA,gBAAAA,CAAgB,IAAA,GAAGC,8BAAAA,gBAAAA,CAAgB,GAAG,EACrD,SAAS,cACX,CAAC,CACH;CAEAC,GAAAA,sBAAAA,aAAAA,CAAa,QAAQ,UAAU,UAAU"}
@@ -1,4 +1,4 @@
1
- import { globalObject } from "@datadog/browser-core";
1
+ import { globalObject } from "@datadog/js-core/util";
2
2
  //#region src/boot/patchSandboxedIframeApis.ts
3
3
  /**
4
4
  * A Shopify Custom Pixel runs in a "lax" sandboxed iframe (`sandbox="allow-scripts"`, no
@@ -9,19 +9,18 @@ import { globalObject } from "@datadog/browser-core";
9
9
  * - `cookieStore.getAll()` is blocked; `document.cookie` works fine as a fallback.
10
10
  * - `navigator.locks.request()` throws a synchronous `SecurityError` (the Web Locks API is
11
11
  * denied without Permissions Policy delegation), but the SDK only catches an async rejection.
12
- * - `getPristineWindow()` creates a nested iframe to read an unpatched `URL` constructor; that
13
- * nested iframe's `contentWindow` is cross-origin here, and reading a property off it throws.
12
+ * - `document.hasFocus()` always returns `false`: the pixel iframe has no focusable UI, so it can
13
+ * never hold browser focus regardless of whether the customer is actively looking at the page.
14
14
  * 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`).
15
+ * (`document.cookie`, same-document promise chaining, `globalObject.URL`, always-focused state).
16
16
  */
17
17
  function patchSandboxedIframeApis() {
18
18
  disableProperty(globalObject, "cookieStore");
19
19
  disableProperty(navigator, "locks");
20
- Object.defineProperty(HTMLIFrameElement.prototype, "contentWindow", {
21
- get() {
22
- return null;
23
- },
24
- configurable: true
20
+ Object.defineProperty(document, "hasFocus", {
21
+ value: () => true,
22
+ configurable: true,
23
+ writable: true
25
24
  });
26
25
  }
27
26
  function disableProperty(target, key) {
@@ -1 +1 @@
1
- {"version":3,"file":"patchSandboxedIframeApis.mjs","names":[],"sources":["../../src/boot/patchSandboxedIframeApis.ts"],"sourcesContent":["import { globalObject } from '@datadog/browser-core'\n\n/**\n * A Shopify Custom Pixel runs in a \"lax\" sandboxed iframe (`sandbox=\"allow-scripts\"`, no\n * `allow-same-origin`): it shares the parent page's cookie jar (same domain) but has an\n * opaque/`null` origin for its own window/document. Several browser APIs the RUM SDK relies on\n * either don't work there or throw synchronously in ways the SDK doesn't fully guard against,\n * which silently breaks session tracking and view/URL resolution:\n * - `cookieStore.getAll()` is blocked; `document.cookie` works fine as a fallback.\n * - `navigator.locks.request()` throws a synchronous `SecurityError` (the Web Locks API is\n * denied without Permissions Policy delegation), but the SDK only catches an async rejection.\n * - `getPristineWindow()` creates a nested iframe to read an unpatched `URL` constructor; that\n * nested iframe's `contentWindow` is cross-origin here, and reading a property off it throws.\n * Shimming these away makes the SDK fall back to code paths that do work in this context\n * (`document.cookie`, same-document promise chaining, `globalObject.URL`).\n */\nexport function patchSandboxedIframeApis() {\n disableProperty(globalObject, 'cookieStore')\n disableProperty(navigator, 'locks')\n\n Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {\n get() {\n return null\n },\n configurable: true,\n })\n}\n\nfunction disableProperty(target: object, key: string) {\n Object.defineProperty(target, key, {\n value: undefined,\n configurable: true,\n writable: true,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,2BAA2B;CACzC,gBAAgB,cAAc,aAAa;CAC3C,gBAAgB,WAAW,OAAO;CAElC,OAAO,eAAe,kBAAkB,WAAW,iBAAiB;EAClE,MAAM;GACJ,OAAO;EACT;EACA,cAAc;CAChB,CAAC;AACH;AAEA,SAAS,gBAAgB,QAAgB,KAAa;CACpD,OAAO,eAAe,QAAQ,KAAK;EACjC,OAAO,KAAA;EACP,cAAc;EACd,UAAU;CACZ,CAAC;AACH"}
1
+ {"version":3,"file":"patchSandboxedIframeApis.mjs","names":[],"sources":["../../src/boot/patchSandboxedIframeApis.ts"],"sourcesContent":["/**\n * A Shopify Custom Pixel runs in a \"lax\" sandboxed iframe (`sandbox=\"allow-scripts\"`, no\n * `allow-same-origin`): it shares the parent page's cookie jar (same domain) but has an\n * opaque/`null` origin for its own window/document. Several browser APIs the RUM SDK relies on\n * either don't work there or throw synchronously in ways the SDK doesn't fully guard against,\n * which silently breaks session tracking and view/URL resolution:\n * - `cookieStore.getAll()` is blocked; `document.cookie` works fine as a fallback.\n * - `navigator.locks.request()` throws a synchronous `SecurityError` (the Web Locks API is\n * denied without Permissions Policy delegation), but the SDK only catches an async rejection.\n * - `document.hasFocus()` always returns `false`: the pixel iframe has no focusable UI, so it can\n * never hold browser focus regardless of whether the customer is actively looking at the page.\n * Shimming these away makes the SDK fall back to code paths that do work in this context\n * (`document.cookie`, same-document promise chaining, `globalObject.URL`, always-focused state).\n */\nimport { globalObject } from '@datadog/js-core/util'\nexport function patchSandboxedIframeApis() {\n disableProperty(globalObject, 'cookieStore')\n disableProperty(navigator, 'locks')\n\n Object.defineProperty(document, 'hasFocus', {\n value: () => true,\n configurable: true,\n writable: true,\n })\n}\n\nfunction disableProperty(target: object, key: string) {\n Object.defineProperty(target, key, {\n value: undefined,\n configurable: true,\n writable: true,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,2BAA2B;CACzC,gBAAgB,cAAc,aAAa;CAC3C,gBAAgB,WAAW,OAAO;CAElC,OAAO,eAAe,UAAU,YAAY;EAC1C,aAAa;EACb,cAAc;EACd,UAAU;CACZ,CAAC;AACH;AAEA,SAAS,gBAAgB,QAAgB,KAAa;CACpD,OAAO,eAAe,QAAQ,KAAK;EACjC,OAAO,KAAA;EACP,cAAc;EACd,UAAU;CACZ,CAAC;AACH"}
@@ -20,12 +20,14 @@ function initShopifyBindings(rumPublicApi, analytics) {
20
20
  const error = event.data?.error;
21
21
  const err = new Error(error?.message);
22
22
  err.stack = error?.trace;
23
- rumPublicApi.addError(err, { extension: {
24
- name: error?.extensionName,
25
- target: error?.extensionTarget,
26
- type: error?.type,
27
- appName: error?.appName
28
- } });
23
+ rumPublicApi.addError(err, {
24
+ extensionName: error?.extensionName,
25
+ extensionTarget: error?.extensionTarget,
26
+ extensionErrorType: error?.type,
27
+ appId: error?.appId,
28
+ appName: error?.appName,
29
+ appVersion: error?.appVersion
30
+ });
29
31
  });
30
32
  }
31
33
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"shopifyBindings.mjs","names":[],"sources":["../../src/domain/shopifyBindings.ts"],"sourcesContent":["import type { RumPublicApi } from '@datadog/browser-rum-core'\nimport type { ShopifyAnalyticsApi, ShopifyPixelEvent } from './shopifyAnalytics'\n\nexport interface ElementData {\n id?: string\n}\n\nexport interface ErrorData {\n message?: string\n trace?: string\n extensionName?: string\n extensionTarget?: string\n type?: string\n appName?: string\n}\n\n// Matches /checkouts/*, /checkout, including locale-prefixed paths.\n// Storefront pages never match, so init() is a no-op there: those pages\n// already get a `DD_RUM` instance from the Theme Liquid snippet, and initializing here too would\n// create a second, independent SDK instance double-tracking the same page view.\nconst CHECKOUT_PATH = /\\/(([a-z]{2}(-[a-z0-9]+)?)\\/)?(checkouts?)(\\/|$)/i\n\n/**\n * Wires Shopify Web Pixel standard events to the RUM public API. `analytics` is the sandbox's\n * `analytics` global (or `undefined` outside the sandbox, in which case bindings are skipped).\n */\nexport function initShopifyBindings(rumPublicApi: RumPublicApi, analytics: ShopifyAnalyticsApi | undefined) {\n if (!analytics) {\n return\n }\n\n analytics.subscribe('page_viewed', (event) => {\n const url = event.context?.document?.location?.href\n\n if (!url || !CHECKOUT_PATH.test(url)) {\n return\n }\n\n rumPublicApi.startView({\n url,\n })\n })\n\n analytics.subscribe('clicked', (event: ShopifyPixelEvent<{ element?: ElementData }>) => {\n const element = event.data?.element\n const name = element?.id ?? 'element-without-id'\n rumPublicApi.startAction(name, { type: 'click' })\n rumPublicApi.stopAction(name, { type: 'click' })\n })\n\n // Fires when a Shopify checkout UI extension crashes.\n analytics.subscribe('ui_extension_errored', (event: ShopifyPixelEvent<{ error?: ErrorData }>) => {\n const error = event.data?.error\n const err = new Error(error?.message)\n err.stack = error?.trace\n rumPublicApi.addError(err, {\n extension: {\n name: error?.extensionName,\n target: error?.extensionTarget,\n type: error?.type,\n appName: error?.appName,\n },\n })\n })\n}\n"],"mappings":";AAoBA,MAAM,gBAAgB;;;;;AAMtB,SAAgB,oBAAoB,cAA4B,WAA4C;CAC1G,IAAI,CAAC,WACH;CAGF,UAAU,UAAU,gBAAgB,UAAU;EAC5C,MAAM,MAAM,MAAM,SAAS,UAAU,UAAU;EAE/C,IAAI,CAAC,OAAO,CAAC,cAAc,KAAK,GAAG,GACjC;EAGF,aAAa,UAAU,EACrB,IACF,CAAC;CACH,CAAC;CAED,UAAU,UAAU,YAAY,UAAwD;EAEtF,MAAM,QADU,MAAM,MAAM,QAAA,EACN,MAAM;EAC5B,aAAa,YAAY,MAAM,EAAE,MAAM,QAAQ,CAAC;EAChD,aAAa,WAAW,MAAM,EAAE,MAAM,QAAQ,CAAC;CACjD,CAAC;CAGD,UAAU,UAAU,yBAAyB,UAAoD;EAC/F,MAAM,QAAQ,MAAM,MAAM;EAC1B,MAAM,MAAM,IAAI,MAAM,OAAO,OAAO;EACpC,IAAI,QAAQ,OAAO;EACnB,aAAa,SAAS,KAAK,EACzB,WAAW;GACT,MAAM,OAAO;GACb,QAAQ,OAAO;GACf,MAAM,OAAO;GACb,SAAS,OAAO;EAClB,EACF,CAAC;CACH,CAAC;AACH"}
1
+ {"version":3,"file":"shopifyBindings.mjs","names":[],"sources":["../../src/domain/shopifyBindings.ts"],"sourcesContent":["import type { RumPublicApi } from '@datadog/browser-rum-core'\nimport type { ShopifyAnalyticsApi, ShopifyPixelEvent } from './shopifyAnalytics'\n\nexport interface ElementData {\n id?: string\n}\n\nexport interface ErrorData {\n message?: string\n trace?: string\n extensionName?: string\n extensionTarget?: string\n type?: string\n appId?: string\n appName?: string\n appVersion?: string\n}\n\n// Matches /checkouts/*, /checkout, including locale-prefixed paths.\n// Storefront pages never match, so init() is a no-op there: those pages\n// already get a `DD_RUM` instance from the Theme Liquid snippet, and initializing here too would\n// create a second, independent SDK instance double-tracking the same page view.\nconst CHECKOUT_PATH = /\\/(([a-z]{2}(-[a-z0-9]+)?)\\/)?(checkouts?)(\\/|$)/i\n\n/**\n * Wires Shopify Web Pixel standard events to the RUM public API. `analytics` is the sandbox's\n * `analytics` global (or `undefined` outside the sandbox, in which case bindings are skipped).\n */\nexport function initShopifyBindings(rumPublicApi: RumPublicApi, analytics: ShopifyAnalyticsApi | undefined) {\n if (!analytics) {\n return\n }\n\n analytics.subscribe('page_viewed', (event) => {\n const url = event.context?.document?.location?.href\n\n if (!url || !CHECKOUT_PATH.test(url)) {\n return\n }\n\n rumPublicApi.startView({\n url,\n })\n })\n\n analytics.subscribe('clicked', (event: ShopifyPixelEvent<{ element?: ElementData }>) => {\n const element = event.data?.element\n const name = element?.id ?? 'element-without-id'\n rumPublicApi.startAction(name, { type: 'click' })\n rumPublicApi.stopAction(name, { type: 'click' })\n })\n\n // Fires when a Shopify checkout UI extension crashes.\n analytics.subscribe('ui_extension_errored', (event: ShopifyPixelEvent<{ error?: ErrorData }>) => {\n const error = event.data?.error\n const err = new Error(error?.message)\n err.stack = error?.trace\n rumPublicApi.addError(err, {\n extensionName: error?.extensionName,\n extensionTarget: error?.extensionTarget,\n extensionErrorType: error?.type,\n appId: error?.appId,\n appName: error?.appName,\n appVersion: error?.appVersion,\n })\n })\n}\n"],"mappings":";AAsBA,MAAM,gBAAgB;;;;;AAMtB,SAAgB,oBAAoB,cAA4B,WAA4C;CAC1G,IAAI,CAAC,WACH;CAGF,UAAU,UAAU,gBAAgB,UAAU;EAC5C,MAAM,MAAM,MAAM,SAAS,UAAU,UAAU;EAE/C,IAAI,CAAC,OAAO,CAAC,cAAc,KAAK,GAAG,GACjC;EAGF,aAAa,UAAU,EACrB,IACF,CAAC;CACH,CAAC;CAED,UAAU,UAAU,YAAY,UAAwD;EAEtF,MAAM,QADU,MAAM,MAAM,QAAA,EACN,MAAM;EAC5B,aAAa,YAAY,MAAM,EAAE,MAAM,QAAQ,CAAC;EAChD,aAAa,WAAW,MAAM,EAAE,MAAM,QAAQ,CAAC;CACjD,CAAC;CAGD,UAAU,UAAU,yBAAyB,UAAoD;EAC/F,MAAM,QAAQ,MAAM,MAAM;EAC1B,MAAM,MAAM,IAAI,MAAM,OAAO,OAAO;EACpC,IAAI,QAAQ,OAAO;EACnB,aAAa,SAAS,KAAK;GACzB,eAAe,OAAO;GACtB,iBAAiB,OAAO;GACxB,oBAAoB,OAAO;GAC3B,OAAO,OAAO;GACd,SAAS,OAAO;GAChB,YAAY,OAAO;EACrB,CAAC;CACH,CAAC;AACH"}
@@ -1,9 +1,12 @@
1
1
  import { makeShopifyRumPublicApi } from "../boot/makeShopifyRumPublicApi.mjs";
2
- import { defineGlobal, globalObject } from "@datadog/browser-core";
2
+ import { globalObject } from "@datadog/js-core/util";
3
+ import { defineGlobal } from "@datadog/browser-core";
3
4
  import { makeRumPublicApi } from "@datadog/browser-rum-core";
4
5
  import { makeProfilerApi, makeRecorderApi } from "@datadog/browser-rum/internal";
5
6
  //#region src/entries/main.ts
6
- defineGlobal(globalObject, "DD_RUM", makeShopifyRumPublicApi(makeRumPublicApi(makeRecorderApi(), makeProfilerApi(), { sdkName: "rum-shopify" })));
7
+ const global = globalObject;
8
+ const datadogRum = makeShopifyRumPublicApi(makeRumPublicApi(makeRecorderApi(), makeProfilerApi(), { sdkName: "rum-shopify" }));
9
+ defineGlobal(global, "DD_RUM", datadogRum);
7
10
  //#endregion
8
11
 
9
12
  //# sourceMappingURL=main.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.mjs","names":["global"],"sources":["../../src/entries/main.ts"],"sourcesContent":["import { defineGlobal, globalObject } from '@datadog/browser-core'\nimport type { RumPublicApi } from '@datadog/browser-rum-core'\nimport { makeRumPublicApi } from '@datadog/browser-rum-core'\nimport { makeRecorderApi, makeProfilerApi } from '@datadog/browser-rum/internal'\nimport { makeShopifyRumPublicApi } from '../boot/makeShopifyRumPublicApi'\n\ninterface BrowserWindow {\n DD_RUM?: RumPublicApi\n}\n\nconst global = globalObject as BrowserWindow\n\nconst datadogRum = makeShopifyRumPublicApi(\n makeRumPublicApi(makeRecorderApi(), makeProfilerApi(), {\n sdkName: 'rum-shopify',\n })\n)\n\ndefineGlobal(global, 'DD_RUM', datadogRum)\n"],"mappings":";;;;;AAkBA,aAAaA,cAAQ,UANF,wBACjB,iBAAiB,gBAAgB,GAAG,gBAAgB,GAAG,EACrD,SAAS,cACX,CAAC,CAGqC,CAAC"}
1
+ {"version":3,"file":"main.mjs","names":[],"sources":["../../src/entries/main.ts"],"sourcesContent":["import { globalObject } from '@datadog/js-core/util'\nimport { defineGlobal } from '@datadog/browser-core'\nimport type { RumPublicApi } from '@datadog/browser-rum-core'\nimport { makeRumPublicApi } from '@datadog/browser-rum-core'\nimport { makeRecorderApi, makeProfilerApi } from '@datadog/browser-rum/internal'\nimport { makeShopifyRumPublicApi } from '../boot/makeShopifyRumPublicApi'\n\ninterface BrowserWindow {\n DD_RUM?: RumPublicApi\n}\n\nconst global = globalObject as BrowserWindow\n\nconst datadogRum = makeShopifyRumPublicApi(\n makeRumPublicApi(makeRecorderApi(), makeProfilerApi(), {\n sdkName: 'rum-shopify',\n })\n)\n\ndefineGlobal(global, 'DD_RUM', datadogRum)\n"],"mappings":";;;;;;AAWA,MAAM,SAAS;AAEf,MAAM,aAAa,wBACjB,iBAAiB,gBAAgB,GAAG,gBAAgB,GAAG,EACrD,SAAS,cACX,CAAC,CACH;AAEA,aAAa,QAAQ,UAAU,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/browser-rum-shopify",
3
- "version": "7.8.0",
3
+ "version": "7.10.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "cjs/entries/main.js",
6
6
  "module": "esm/entries/main.mjs",
@@ -14,15 +14,15 @@
14
14
  "!src/**/*.specHelper.ts"
15
15
  ],
16
16
  "scripts": {
17
- "build": "node ../../scripts/build/build-package.ts --modules --bundle datadog-rum-shopify.js",
18
- "build:bundle": "node ../../scripts/build/build-package.ts --bundle datadog-rum-shopify.js",
17
+ "build": "node ../../scripts/build/build-package.ts --modules --worker-string --bundle datadog-rum-shopify.js",
18
+ "build:bundle": "node ../../scripts/build/build-package.ts --worker-string --bundle datadog-rum-shopify.js",
19
19
  "prepack": "yarn build"
20
20
  },
21
21
  "dependencies": {
22
- "@datadog/browser-core": "7.8.0",
23
- "@datadog/browser-rum": "7.8.0",
24
- "@datadog/browser-rum-core": "7.8.0",
25
- "@datadog/js-core": "0.0.9"
22
+ "@datadog/browser-core": "7.10.0",
23
+ "@datadog/browser-rum": "7.10.0",
24
+ "@datadog/browser-rum-core": "7.10.0",
25
+ "@datadog/js-core": "0.0.11"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
@@ -1,5 +1,3 @@
1
- import { globalObject } from '@datadog/browser-core'
2
-
3
1
  /**
4
2
  * A Shopify Custom Pixel runs in a "lax" sandboxed iframe (`sandbox="allow-scripts"`, no
5
3
  * `allow-same-origin`): it shares the parent page's cookie jar (same domain) but has an
@@ -9,20 +7,20 @@ import { globalObject } from '@datadog/browser-core'
9
7
  * - `cookieStore.getAll()` is blocked; `document.cookie` works fine as a fallback.
10
8
  * - `navigator.locks.request()` throws a synchronous `SecurityError` (the Web Locks API is
11
9
  * denied without Permissions Policy delegation), but the SDK only catches an async rejection.
12
- * - `getPristineWindow()` creates a nested iframe to read an unpatched `URL` constructor; that
13
- * nested iframe's `contentWindow` is cross-origin here, and reading a property off it throws.
10
+ * - `document.hasFocus()` always returns `false`: the pixel iframe has no focusable UI, so it can
11
+ * never hold browser focus regardless of whether the customer is actively looking at the page.
14
12
  * 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`).
13
+ * (`document.cookie`, same-document promise chaining, `globalObject.URL`, always-focused state).
16
14
  */
15
+ import { globalObject } from '@datadog/js-core/util'
17
16
  export function patchSandboxedIframeApis() {
18
17
  disableProperty(globalObject, 'cookieStore')
19
18
  disableProperty(navigator, 'locks')
20
19
 
21
- Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
22
- get() {
23
- return null
24
- },
20
+ Object.defineProperty(document, 'hasFocus', {
21
+ value: () => true,
25
22
  configurable: true,
23
+ writable: true,
26
24
  })
27
25
  }
28
26
 
@@ -11,7 +11,9 @@ export interface ErrorData {
11
11
  extensionName?: string
12
12
  extensionTarget?: string
13
13
  type?: string
14
+ appId?: string
14
15
  appName?: string
16
+ appVersion?: string
15
17
  }
16
18
 
17
19
  // Matches /checkouts/*, /checkout, including locale-prefixed paths.
@@ -54,12 +56,12 @@ export function initShopifyBindings(rumPublicApi: RumPublicApi, analytics: Shopi
54
56
  const err = new Error(error?.message)
55
57
  err.stack = error?.trace
56
58
  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,
63
65
  })
64
66
  })
65
67
  }
@@ -1,4 +1,5 @@
1
- import { defineGlobal, globalObject } from '@datadog/browser-core'
1
+ import { globalObject } from '@datadog/js-core/util'
2
+ import { defineGlobal } from '@datadog/browser-core'
2
3
  import type { RumPublicApi } from '@datadog/browser-rum-core'
3
4
  import { makeRumPublicApi } from '@datadog/browser-rum-core'
4
5
  import { makeRecorderApi, makeProfilerApi } from '@datadog/browser-rum/internal'