Skip to content

: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.

feat(replay): route rasterizer Chrome through smokescreen via proxy-chain (#61251)

Tue Haulundab0e1c01812e
diff --git a/bin/temporal-recording-rasterizer-worker b/bin/temporal-recording-rasterizer-worker
index 3b8f9b2501b3..30c41852ceb2 100755
--- a/bin/temporal-recording-rasterizer-worker
+++ b/bin/temporal-recording-rasterizer-worker
@@ -71,12 +71,18 @@ fi
# and uses host.docker.internal for services running natively on the host
# (recording-api, Django).
+# Chrome's namespace-sandbox needs seccomp/apparmor relaxed to bootstrap inside
+# the linux/amd64 emulation Docker uses on macOS. Local dev script only — prod
+# runs from the Helm chart, not this script.
echo "Starting recording-rasterizer container..."
+# nosemgrep: trailofbits.generic.container-privileged.container-privileged
docker run --rm \
--name "$CONTAINER_NAME" \
--network posthog_default \
--platform linux/amd64 \
--add-host localhost:host-gateway \
+ --security-opt seccomp=unconfined \
+ --security-opt apparmor=unconfined \
-e TEMPORAL_HOST="${TEMPORAL_HOST:-posthog-temporal-1}" \
-e TEMPORAL_PORT="${TEMPORAL_PORT:-7233}" \
-e RECORDING_API_BASE_URL="${RECORDING_API_BASE_URL:-http://host.docker.internal:6741}" \
diff --git a/nodejs/src/session-replay/recording-rasterizer/__tests__/browser-pool.test.ts b/nodejs/src/session-replay/recording-rasterizer/__tests__/browser-pool.test.ts
index a59067db1cd8..ac72d4557bcf 100644
--- a/nodejs/src/session-replay/recording-rasterizer/__tests__/browser-pool.test.ts
+++ b/nodejs/src/session-replay/recording-rasterizer/__tests__/browser-pool.test.ts
@@ -26,6 +26,8 @@ jest.mock(
const puppeteerCapture = require('puppeteer-capture')
+const ORIGINAL_ENV = process.env
+
function mockBrowser(): jest.Mocked<Browser> {
return {
newPage: jest.fn(),
@@ -44,13 +46,20 @@ describe('BrowserPool', () => {
beforeEach(() => {
jest.clearAllMocks()
+ process.env = { ...ORIGINAL_ENV }
+ delete process.env.HTTPS_PROXY
+ delete process.env.HTTP_PROXY
+ delete process.env.https_proxy
+ delete process.env.http_proxy
+ delete process.env.RASTERIZER_USE_PROXY
})
afterEach(async () => {
await pool?.shutdown()
+ process.env = ORIGINAL_ENV
})
- it('launches a browser on getPage', async () => {
+ it('launches a browser on getPage with no --proxy-server when no proxy env is set', async () => {
const browser = mockBrowser()
const page = mockPage()
browser.newPage.mockResolvedValue(page)
@@ -62,6 +71,8 @@ describe('BrowserPool', () => {
expect(puppeteerCapture.launch).toHaveBeenCalledTimes(1)
expect(result).toBe(page)
expect(pool.stats).toEqual({ usageCount: 1, activePages: 1 })
+ const launchArgs = puppeteerCapture.launch.mock.calls[0][0].args as string[]
+ expect(launchArgs.some((a) => a.startsWith('--proxy-server'))).toBe(false)
})
it('launches separate browsers for concurrent pages', async () => {
@@ -193,4 +204,87 @@ describe('BrowserPool', () => {
await expect(pool.releaseAllPages()).resolves.not.toThrow()
expect(pool.stats.activePages).toBe(0)
})
+
+ describe('proxy resolution', () => {
+ it.each([
+ { source: 'HTTPS_PROXY', env: 'HTTPS_PROXY' as const },
+ { source: 'HTTP_PROXY fallback', env: 'HTTP_PROXY' as const },
+ { source: 'lowercase https_proxy', env: 'https_proxy' as const },
+ { source: 'lowercase http_proxy', env: 'http_proxy' as const },
+ ])('points Chrome at upstream from $source', async ({ env }) => {
+ process.env[env] = 'http://smokescreen.smokescreen.svc.cluster.local:4750/'
+ const browser = mockBrowser()
+ browser.newPage.mockResolvedValue(mockPage())
+ puppeteerCapture.launch.mockResolvedValue(browser)
+
+ pool = new BrowserPool(100)
+ await pool.launch()
+
+ const launchArgs = puppeteerCapture.launch.mock.calls[0][0].args as string[]
+ expect(launchArgs).toContain('--proxy-server=http://smokescreen.smokescreen.svc.cluster.local:4750')
+ // Override Chrome's implicit loopback bypass so loopback /
+ // link-local destinations still go through the proxy.
+ expect(launchArgs).toContain('--proxy-bypass-list=<-loopback>')
+ })
+
+ it.each(['smokescreen:4750', 'not a url'])(
+ 'throws fast at construction when proxy env var %j is not a valid URL with a host',
+ (value) => {
+ process.env.HTTPS_PROXY = value
+ expect(() => new BrowserPool(100)).toThrow()
+ }
+ )
+
+ it('strips userinfo and path from upstream when forming --proxy-server', async () => {
+ process.env.HTTPS_PROXY = 'http://user:pass@smokescreen:4750/somepath'
+ const browser = mockBrowser()
+ browser.newPage.mockResolvedValue(mockPage())
+ puppeteerCapture.launch.mockResolvedValue(browser)
+
+ pool = new BrowserPool(100)
+ await pool.launch()
+
+ const launchArgs = puppeteerCapture.launch.mock.calls[0][0].args as string[]
+ expect(launchArgs).toContain('--proxy-server=http://smokescreen:4750')
+ // Make sure nothing matching user:pass leaked
+ expect(launchArgs.find((a) => a.includes('user:pass'))).toBeUndefined()
+ })
+
+ it.each(['false', 'False', 'FALSE', '0', 'no', 'off', ' false '])(
+ 'RASTERIZER_USE_PROXY=%j short-circuits the proxy even when HTTPS_PROXY is set',
+ async (value) => {
+ process.env.HTTPS_PROXY = 'http://smokescreen:4750/'
+ process.env.RASTERIZER_USE_PROXY = value
+ const browser = mockBrowser()
+ browser.newPage.mockResolvedValue(mockPage())
+ puppeteerCapture.launch.mockResolvedValue(browser)
+
+ pool = new BrowserPool(100)
+ await pool.launch()
+
+ const launchArgs = puppeteerCapture.launch.mock.calls[0][0].args as string[]
+ expect(launchArgs.some((a) => a.startsWith('--proxy-server'))).toBe(false)
+ expect(launchArgs.some((a) => a.startsWith('--proxy-bypass-list'))).toBe(false)
+ }
+ )
+
+ it.each(['true', '1', '', 'enabled', 'disabled', 'yes'])(
+ 'RASTERIZER_USE_PROXY=%j leaves proxy on (only known falsy values disable)',
+ async (value) => {
+ process.env.HTTPS_PROXY = 'http://smokescreen:4750/'
+ if (value !== '') {
+ process.env.RASTERIZER_USE_PROXY = value
+ }
+ const browser = mockBrowser()
+ browser.newPage.mockResolvedValue(mockPage())
+ puppeteerCapture.launch.mockResolvedValue(browser)
+
+ pool = new BrowserPool(100)
+ await pool.launch()
+
+ const launchArgs = puppeteerCapture.launch.mock.calls[0][0].args as string[]
+ expect(launchArgs).toContain('--proxy-server=http://smokescreen:4750')
+ }
+ )
+ })
})
diff --git a/nodejs/src/session-replay/recording-rasterizer/capture/browser-pool.ts b/nodejs/src/session-replay/recording-rasterizer/capture/browser-pool.ts
index b63f5b8747dd..f34a6a33b8fa 100644
--- a/nodejs/src/session-replay/recording-rasterizer/capture/browser-pool.ts
+++ b/nodejs/src/session-replay/recording-rasterizer/capture/browser-pool.ts
@@ -7,13 +7,40 @@ import { RasterizationMetrics } from '../metrics'
const log = createLogger()
-const LAUNCH_ARGS = [
- '--disable-dev-shm-usage',
- '--mute-audio',
- ...(process.env.CHROME_HOST_RESOLVER_RULES
- ? [`--host-resolver-rules=${process.env.CHROME_HOST_RESOLVER_RULES}`]
- : []),
-]
+function resolveProxyArgs(): string[] {
+ const killed = ['false', '0', 'no', 'off'].includes((process.env.RASTERIZER_USE_PROXY ?? '').trim().toLowerCase())
+ const upstream =
+ process.env.HTTPS_PROXY || process.env.HTTP_PROXY || process.env.https_proxy || process.env.http_proxy
+ if (!upstream) {
+ return []
+ }
+ if (killed) {
+ log.warn(
+ { RASTERIZER_USE_PROXY: process.env.RASTERIZER_USE_PROXY },
+ 'RASTERIZER_USE_PROXY disables egress proxy — chrome will dial direct'
+ )
+ return []
+ }
+ // Chrome's --proxy-server takes scheme://host:port — drop userinfo / path.
+ // `new URL("smokescreen:4750")` parses as scheme-only with empty host; fail
+ // fast rather than silently rendering --proxy-server=smokescreen:// (which
+ // would bypass the proxy and break egress containment).
+ const u = new URL(upstream)
+ if (!u.host) {
+ throw new Error(
+ `Egress proxy URL has no host — pass a fully-qualified URL like http://smokescreen:4750, not "${upstream}"`
+ )
+ }
+ const proxyServer = `${u.protocol}//${u.host}`
+ log.info({ proxy_server: proxyServer }, 'chrome routing egress through proxy')
+ return [
+ `--proxy-server=${proxyServer}`,
+ // Override Chrome's implicit loopback/link-local bypass so customer
+ // DOM pointing at localhost / 127.0.0.1 / 169.254.169.254 (IMDS)
+ // still goes through the proxy.
+ '--proxy-bypass-list=<-loopback>',
+ ]
+}
interface BrowserSlot {
browser: Browser
@@ -23,14 +50,26 @@ interface BrowserSlot {
export class BrowserPool {
private slots = new Map<Page, BrowserSlot>()
private idle: BrowserSlot[] = []
+ private proxyArgs = resolveProxyArgs()
constructor(private recycleAfter: number = config.browserRecycleAfter) {}
+ private launchArgs(): string[] {
+ return [
+ '--disable-dev-shm-usage',
+ '--mute-audio',
+ ...this.proxyArgs,
+ ...(config.disableBrowserSecurity ? ['--disable-web-security'] : []),
+ ...(process.env.CHROME_HOST_RESOLVER_RULES
+ ? [`--host-resolver-rules=${process.env.CHROME_HOST_RESOLVER_RULES}`]
+ : []),
+ ]
+ }
+
private async launchBrowser(): Promise<BrowserSlot> {
- const args = config.disableBrowserSecurity ? [...LAUNCH_ARGS, '--disable-web-security'] : LAUNCH_ARGS
const browser = await launchForCapture({
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined,
- args,
+ args: this.launchArgs(),
})
RasterizationMetrics.browserLaunched()
return { browser, usageCount: 0 }
@@ -45,7 +84,6 @@ export class BrowserPool {
}
async launch(): Promise<void> {
- // Pre-warm one browser so the first getPage() is fast
if (this.idle.length === 0) {
this.idle.push(await this.launchBrowser())
}
@@ -58,7 +96,6 @@ export class BrowserPool {
} else {
slot = await this.launchBrowser()
}
-
const page = await slot.browser.newPage()
slot.usageCount++
this.slots.set(page, slot)
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 765290665b0c..516a4c5521bc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -440,7 +440,7 @@ importers:
'@storybook/react-webpack5':
specifier: ^8.6.14
'@storybook/test-runner':
specifier: ^0.19.1
@@ -494,7 +494,7 @@ importers:
version: 2.0.0([email protected])
webpack:
specifier: 5.88.2
webpack-cli:
specifier: ^5.1.4
version: 5.1.4([email protected])
@@ -31940,7 +31940,7 @@ snapshots:
ts-dedent: 2.2.0
dependencies:
'@storybook/core-webpack': 8.6.18([email protected]([email protected]))
'@types/semver': 7.7.1
@@ -31958,12 +31958,12 @@ snapshots:
semver: 7.8.0
storybook: 8.6.18([email protected])
style-loader: 3.3.3([email protected])
+ terser-webpack-plugin: 5.6.0([email protected])([email protected])
ts-dedent: 2.2.0
url: 0.11.1
util: 0.12.5
util-deprecate: 1.0.2
webpack-dev-middleware: 6.1.3([email protected])
webpack-hot-middleware: 2.25.4
webpack-virtual-modules: 0.6.2
@@ -32057,7 +32057,7 @@ snapshots:
dependencies:
storybook: 8.6.18([email protected])
dependencies:
'@storybook/core-webpack': 8.6.18([email protected]([email protected]))
@@ -32072,7 +32072,7 @@ snapshots:
semver: 7.8.0
storybook: 8.6.18([email protected])
tsconfig-paths: 4.2.0
optionalDependencies:
typescript: 6.0.3
transitivePeerDependencies:
@@ -32106,7 +32106,7 @@ snapshots:
react-docgen-typescript: 2.2.2([email protected])
tslib: 2.8.1
typescript: 6.0.3
transitivePeerDependencies:
- supports-color
@@ -32144,10 +32144,10 @@ snapshots:
- supports-color
- typescript
dependencies:
react: 18.3.1
react-dom: 18.3.1([email protected])
@@ -34511,17 +34511,17 @@ snapshots:
dependencies:
webpack-cli: 5.1.4([email protected])
dependencies:
webpack-cli: 5.1.4([email protected])
dependencies:
webpack-cli: 5.1.4([email protected])
'@xmldom/[email protected]': {}
@@ -35090,7 +35090,7 @@ snapshots:
loader-utils: 2.0.4
make-dir: 3.1.0
schema-utils: 2.7.1
dependencies:
@@ -36195,7 +36195,7 @@ snapshots:
postcss-value-parser: 4.2.0
schema-utils: 2.7.1
semver: 6.3.1
dependencies:
@@ -36207,7 +36207,7 @@ snapshots:
postcss-modules-values: 4.0.0([email protected])
postcss-value-parser: 4.2.0
semver: 7.8.0
dependencies:
@@ -37791,7 +37791,7 @@ snapshots:
dependencies:
loader-utils: 2.0.4
schema-utils: 3.3.0
@@ -37910,7 +37910,7 @@ snapshots:
semver: 7.8.0
tapable: 2.3.0
typescript: 6.0.3
dependencies:
@@ -38573,7 +38573,7 @@ snapshots:
dependencies:
html-webpack-plugin: 5.5.3([email protected])
dependencies:
@@ -38582,7 +38582,7 @@ snapshots:
lodash: 4.18.1
pretty-error: 4.0.0
tapable: 2.2.1
dependencies:
@@ -40827,7 +40827,7 @@ snapshots:
less: 4.2.2
loader-utils: 2.0.4
schema-utils: 3.3.0
dependencies:
@@ -43145,7 +43145,7 @@ snapshots:
postcss: 8.5.15
schema-utils: 3.3.0
semver: 7.7.0
dependencies:
@@ -43932,7 +43932,7 @@ snapshots:
dependencies:
loader-utils: 2.0.4
schema-utils: 3.3.0
dependencies:
@@ -44996,7 +44996,7 @@ snapshots:
neo-async: 2.6.2
schema-utils: 3.3.0
semver: 7.7.0
optionalDependencies:
sass: 1.56.0
@@ -45660,11 +45660,11 @@ snapshots:
dependencies:
loader-utils: 2.0.4
schema-utils: 3.3.0
dependencies:
@@ -46029,28 +46029,26 @@ snapshots:
ansi-escapes: 4.3.2
supports-hyperlinks: 2.3.0
dependencies:
'@jridgewell/trace-mapping': 0.3.29
jest-worker: 27.5.1
schema-utils: 4.3.3
terser: 5.46.0
optionalDependencies:
'@swc/core': 1.15.18
- esbuild: 0.25.12
+ esbuild: 0.27.7
postcss: 8.5.15
dependencies:
'@jridgewell/trace-mapping': 0.3.29
jest-worker: 27.5.1
schema-utils: 4.3.3
terser: 5.46.0
optionalDependencies:
- '@swc/core': 1.15.18
- esbuild: 0.27.7
postcss: 8.5.15
@@ -47244,7 +47242,7 @@ snapshots:
import-local: 3.1.0
interpret: 3.1.1
rechoir: 0.8.0
webpack-merge: 5.8.0
@@ -47255,7 +47253,7 @@ snapshots:
range-parser: 1.2.1
schema-utils: 4.3.3
optionalDependencies:
dependencies:
@@ -47315,7 +47313,7 @@ snapshots:
- postcss
- uglify-js
dependencies:
'@types/eslint-scope': 3.7.7
'@types/estree': 1.0.8
@@ -47338,7 +47336,7 @@ snapshots:
neo-async: 2.6.2
schema-utils: 3.3.0
tapable: 2.3.0
+ terser-webpack-plugin: 5.6.0([email protected])([email protected])
watchpack: 2.5.1
webpack-sources: 3.3.4
optionalDependencies: