:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(replay): hide translator extension popup injected into recorded pages (#98197)
Hayne Ryu01158a3b2f9a
diff --git a/common/replay-shared/src/rrweb-plugins/common-replayer-config.test.ts b/common/replay-shared/src/rrweb-plugins/common-replayer-config.test.tsindex 078cd06a5de9..4eeac7bbeaa7 100644--- a/common/replay-shared/src/rrweb-plugins/common-replayer-config.test.ts+++ b/common/replay-shared/src/rrweb-plugins/common-replayer-config.test.ts@@ -1,3 +1,6 @@+/**+ * @jest-environment jsdom+ */import { COMMON_REPLAYER_CONFIG } from './index'// posthog-js/* ships ESM that the test transform can't load directly; these values are@@ -19,4 +22,41 @@ describe('COMMON_REPLAYER_CONFIG', () => {// PostHog renders canvas via CanvasReplayerPlugin instead, so this must stay off.expect(COMMON_REPLAYER_CONFIG.UNSAFE_replayCanvas).toBe(false)})++ describe('extension popup rule', () => {+ const parseShippedRule = (): CSSStyleRule => {+ const css = COMMON_REPLAYER_CONFIG.insertStyleRules?.find((rule) => rule.includes('translate-tooltip-mtz'))+ const style = document.createElement('style')+ style.textContent = css ?? ''+ document.head.appendChild(style)+ const rules = [...(style.sheet?.cssRules ?? [])]+ expect(rules).toHaveLength(1)+ return rules[0] as CSSStyleRule+ }++ it('hides what it matches', () => {+ expect(parseShippedRule().style.display).toBe('none')+ })++ it.each([+ ['div', 'translate-tooltip-mtz blue sm-root translate hidden_translate', true],+ ['span', 'translate-button-mtz hidden_translate blue', true],+ ['div', 'app-content', false],+ ])('page-level %s.%s hidden: %s', (tagName, className, expected) => {+ const el = document.createElement(tagName)+ el.className = className+ document.body.appendChild(el)+ expect(el.matches(parseShippedRule().selectorText)).toBe(expected)+ })++ it('leaves an identically named element inside the recorded page alone', () => {+ // Matching below <body> could hide a customer's own content and blank the replay.+ const app = document.createElement('div')+ const nested = document.createElement('div')+ nested.className = 'translate-tooltip-mtz'+ app.appendChild(nested)+ document.body.appendChild(app)+ expect(nested.matches(parseShippedRule().selectorText)).toBe(false)+ })+ })})diff --git a/common/replay-shared/src/rrweb-plugins/index.ts b/common/replay-shared/src/rrweb-plugins/index.tsindex 00f553d24e8a..a740cb4bbc47 100644--- a/common/replay-shared/src/rrweb-plugins/index.ts+++ b/common/replay-shared/src/rrweb-plugins/index.ts@@ -66,10 +66,14 @@ export const CorsPlugin: ReplayPlugin & {const defaultStyleRules = `.ph-no-capture { background-image: ${PLACEHOLDER_SVG_DATA_IMAGE_URL}; }`const shopifyShorthandCSSFix ='@media (prefers-reduced-motion: no-preference) { .scroll-trigger:not(.scroll-trigger--offscreen).animate--slide-in { animation: var(--animation-slide-in) } }'+// Language picker prepended to <body> by the "Translator, dictionary - accurate translate" extension.+// Its hiding CSS is content-script-only, so unrecordable; without this the picker reflows the page.+const translatorExtensionPopupFix =+ 'body > div.translate-tooltip-mtz, body > span.translate-button-mtz { display: none !important; }'export const COMMON_REPLAYER_CONFIG: Partial<playerConfig> = {triggerFocus: false,- insertStyleRules: [defaultStyleRules, shopifyShorthandCSSFix],+ insertStyleRules: [defaultStyleRules, shopifyShorthandCSSFix, translatorExtensionPopupFix],// Keep the replay iframe scriptless. UNSAFE_replayCanvas makes rrweb add `allow-scripts`// to the sandbox, which combined with the required `allow-same-origin` lets untrusted// recorded content escape the sandbox into the app origin. Canvas is replayed via