Skip to content

test: add playwright script that proxies Amplitude scripts to test customer pages#1682

Open
daniel-graham-amplitude wants to merge 11 commits intomainfrom
ai-week-playwright-mcp
Open

test: add playwright script that proxies Amplitude scripts to test customer pages#1682
daniel-graham-amplitude wants to merge 11 commits intomainfrom
ai-week-playwright-mcp

Conversation

@daniel-graham-amplitude
Copy link
Copy Markdown
Collaborator

@daniel-graham-amplitude daniel-graham-amplitude commented Apr 15, 2026

Summary

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Note

Low Risk
Primarily additive, developer-only tooling (new script, docs, and dev dependency) with no changes to shipped SDK runtime behavior; main risk is local/CI dependency footprint from adding playwright.

Overview
Adds e2e/manual-test.js, a headed Playwright script that proxies a provided website URL, rewrites requests for Amplitude CDN bundles to either the local Vite dev server (pnpm dev:ssh) or specific pinned CDN versions via env vars, and optionally rewrites ingest calls to use a supplied AMPLITUDE_API_KEY.

The proxy also strips known SRI integrity hashes from top-level HTML and GTM-injected scripts and normalizes response headers to avoid encoding/length mismatches during fulfillment. Supporting changes include adding playwright as a root dev dependency, extending .gitignore for Playwright MCP artifacts, and adding a Cursor skill doc describing the workflow.

Reviewed by Cursor Bugbot for commit 12033d2. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for all 3 issues found in the latest run.

  • ✅ Fixed: Playwright added as production dependency instead of dev
    • Moved playwright from dependencies to devDependencies so it is not installed in production contexts.
  • ✅ Fixed: Playwright version mismatch with @playwright/test dependency
    • Pinned playwright to 1.55.0 to match the existing @playwright/test version and updated lockfile entries accordingly.
  • ✅ Fixed: ESM import syntax in .js without "type": "module"
    • Converted e2e/manual-test.js to CommonJS (require) and corrected usage text/comments so it runs with plain Node.js.

Create PR

Or push these changes by commenting:

@cursor push 7665094b95
Preview (7665094b95)
diff --git a/e2e/manual-test.js b/e2e/manual-test.js
--- a/e2e/manual-test.js
+++ b/e2e/manual-test.js
@@ -1,12 +1,12 @@
-// playwright-proxy.ts
-import { chromium } from 'playwright';
+// playwright-proxy.js
+const { chromium } = require('playwright');
 
 // Get URL from command line args
 const targetUrl = process.argv[2];
 
 if (!targetUrl) {
-  console.error('Usage: npx ts-node playwright-proxy.ts <url>');
-  console.error('Example: npx ts-node playwright-proxy.ts https://example.com');
+  console.error('Usage: node e2e/manual-test.js <url>');
+  console.error('Example: node e2e/manual-test.js https://example.com');
   process.exit(1);
 }
 

diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -78,6 +78,7 @@
     "morgan": "^1.10.0",
     "nodemon": "^3.0.1",
     "nx": "^21.2.1",
+    "playwright": "1.55.0",
     "prettier": "^2.8.1",
     "rimraf": "^3.0.2",
     "source-map": "^0.7.4",
@@ -95,7 +96,6 @@
     ]
   },
   "dependencies": {
-    "playwright": "^1.59.1",
     "tslib": "^2.4.1"
   },
   "packageManager": "pnpm@10.26.1+sha512.664074abc367d2c9324fdc18037097ce0a8f126034160f709928e9e9f95d98714347044e5c3164d65bd5da6c59c6be362b107546292a8eecb7999196e5ce58fa"

diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -8,9 +8,6 @@
 
   .:
     dependencies:
-      playwright:
-        specifier: ^1.59.1
-        version: 1.59.1
       tslib:
         specifier: ^2.4.1
         version: 2.8.1
@@ -111,6 +108,9 @@
       nx:
         specifier: ^21.2.1
         version: 21.6.8
+      playwright:
+        specifier: 1.55.0
+        version: 1.55.0
       prettier:
         specifier: ^2.8.1
         version: 2.8.8

You can send follow-ups to the cloud agent here.

Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread e2e/manual-test.js
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 4 total unresolved issues (including 3 from previous reviews).

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Usage error message references wrong filename and command
    • Updated e2e/manual-test.js to reference the correct script filename and invocation command in both the header comment and missing-argument usage/example messages.

Create PR

Or push these changes by commenting:

@cursor push d8388b0d1d
Preview (d8388b0d1d)
diff --git a/e2e/manual-test.js b/e2e/manual-test.js
--- a/e2e/manual-test.js
+++ b/e2e/manual-test.js
@@ -1,12 +1,12 @@
-// playwright-proxy.ts
+// manual-test.js
 import { chromium } from 'playwright';
 
 // Get URL from command line args
 const targetUrl = process.argv[2];
 
 if (!targetUrl) {
-  console.error('Usage: npx ts-node playwright-proxy.ts <url>');
-  console.error('Example: npx ts-node playwright-proxy.ts https://example.com');
+  console.error('Usage: node ./e2e/manual-test.js <website-url>');
+  console.error('Example: node ./e2e/manual-test.js https://example.com');
   process.exit(1);
 }

You can send follow-ups to the cloud agent here.

Comment thread e2e/manual-test.js Outdated
@daniel-graham-amplitude daniel-graham-amplitude changed the title add playwright script that proxies unified scripts on customer pages test: add playwright script that proxies Amplitude scripts to test customer pages Apr 16, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

There are 4 total unresolved issues (including 1 from previous review).

Autofix Details

Bugbot Autofix prepared fixes for all 3 issues found in the latest run.

  • ✅ Fixed: replace only strips first occurrence of each hash
    • Replaced hash stripping calls with replaceAll so every occurrence of each integrity hash is removed in GTM and document rewrite paths.
  • ✅ Fixed: Redundant duplicate hash stripping for HTML documents
    • Removed the second HTML-specific integrity stripping loop and fulfilled HTML responses directly from the already-stripped content.
  • ✅ Fixed: Non-HTML fulfill path missing encoding header removal
    • Updated the non-HTML fulfill branch to set status and dropped encoding/length headers before returning the decompressed text body.

Create PR

Or push these changes by commenting:

@cursor push 8a47623b97
Preview (8a47623b97)
diff --git a/e2e/manual-test.js b/e2e/manual-test.js
--- a/e2e/manual-test.js
+++ b/e2e/manual-test.js
@@ -71,7 +71,7 @@
         const response = await route.fetch();
         let body = await response.text();
         for (const hash of INTEGRITY_HASHES) {
-          body = body.replace(hash, '');
+          body = body.replaceAll(hash, '');
         }
         await route.fulfill({
           status: response.status(),
@@ -102,23 +102,22 @@
     }
     let content = await response.text();
     for (const hash of INTEGRITY_HASHES) {
-      content = content.replace(hash, '');
+      content = content.replaceAll(hash, '');
     }
 
     const ct = (response.headers()['content-type'] || '').toLowerCase();
     if (!ct.includes('text/html')) {
-      return route.fulfill({ response, body: content });
+      return route.fulfill({
+        status: response.status(),
+        headers: dropEncodingHeaders(response.headers()),
+        body: content,
+      });
     }
-    let html = content;
 
-    for (const hash of INTEGRITY_HASHES) {
-      html = html.replace(hash, '');
-    }
-
     await route.fulfill({
       status: response.status(),
       headers: dropEncodingHeaders(response.headers()),
-      body: html,
+      body: content,
     });
   });

You can send follow-ups to the cloud agent here.

Comment thread e2e/manual-test.js
Comment thread e2e/manual-test.js
Comment thread e2e/manual-test.js Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 5 total unresolved issues (including 4 from previous reviews).

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Debug console.log accidentally committed in production SDK
    • Removed the accidental console.log('AI WEEK CODING CHANGES') from AmplitudeBrowser.init so SDK initialization no longer emits debug output.

Create PR

Or push these changes by commenting:

@cursor push 337b19c541
Preview (337b19c541)
diff --git a/packages/analytics-browser/src/browser-client.ts b/packages/analytics-browser/src/browser-client.ts
--- a/packages/analytics-browser/src/browser-client.ts
+++ b/packages/analytics-browser/src/browser-client.ts
@@ -97,7 +97,6 @@
   init(apiKey = '', userIdOrOptions?: string | BrowserOptions, maybeOptions?: BrowserOptions) {
     let userId: string | undefined;
     let options: BrowserOptions | undefined;
-    console.log('AI WEEK CODING CHANGES');
     if (arguments.length > 2) {
       userId = userIdOrOptions as string | undefined;
       options = maybeOptions;

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit c6f000e. Configure here.

Comment thread packages/analytics-browser/src/browser-client.ts Outdated
Copy link
Copy Markdown
Contributor

@Mercy811 Mercy811 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Dan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants