[object Object]

← back to Delivery Address Fix

5x sweep 1: playwright global-root fallback resolver (repo has no node_modules; require('playwright') failed everywhere)

1b1b3149abb7f9ffc32cd97901aaea7ef5d0e91b · 2026-08-02 16:09:34 -0700 · Steve Abrams

Files touched

Diff

commit 1b1b3149abb7f9ffc32cd97901aaea7ef5d0e91b
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Sun Aug 2 16:09:34 2026 -0700

    5x sweep 1: playwright global-root fallback resolver (repo has no node_modules; require('playwright') failed everywhere)
---
 scripts/browser-server.js |  3 ++-
 scripts/launch.js         |  4 ++--
 scripts/lib.js            | 22 ++++++++++++++++++++--
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/scripts/browser-server.js b/scripts/browser-server.js
index 4dba847..fe37ba2 100644
--- a/scripts/browser-server.js
+++ b/scripts/browser-server.js
@@ -1,6 +1,7 @@
 // Long-lived headed real-Chrome session with CDP for step scripts.
 // Generic launcher: node browser-server.js <profileDir> <cdpPort> <startUrl>
-const { chromium } = require('playwright');
+const { requirePlaywright } = require('./lib');
+const { chromium } = requirePlaywright();
 const [profileDir, cdpPort, startUrl] = process.argv.slice(2);
 if (!profileDir || !cdpPort || !startUrl) {
   console.error('usage: node browser-server.js <profileDir> <cdpPort> <startUrl>');
diff --git a/scripts/launch.js b/scripts/launch.js
index 0ccec9b..5430a75 100644
--- a/scripts/launch.js
+++ b/scripts/launch.js
@@ -1,8 +1,8 @@
 // Launch a long-lived headed real-Chrome session with CDP for the relay scripts.
 // Usage: node launch.js --platform ubereats --user me@example.com [--port 9223]
 const path = require('path');
-const { chromium } = require('playwright');
-const { parseArgs, loadConfig, platform } = require('./lib');
+const { parseArgs, loadConfig, platform, requirePlaywright } = require('./lib');
+const { chromium } = requirePlaywright();
 
 (async () => {
   const args = parseArgs(process.argv);
diff --git a/scripts/lib.js b/scripts/lib.js
index ce04202..911eea9 100644
--- a/scripts/lib.js
+++ b/scripts/lib.js
@@ -26,6 +26,24 @@ const PLATFORMS = {
   },
 };
 
+// playwright isn't vendored (no node_modules in this repo) — fall back to the
+// machine's global npm roots when a plain require can't resolve it.
+function requirePlaywright() {
+  try { return require('playwright'); } catch (e) {
+    const roots = [
+      path.join(process.env.HOME || '', '.npm-global', 'lib', 'node_modules'),
+      '/opt/homebrew/lib/node_modules',
+      '/usr/local/lib/node_modules',
+    ];
+    for (const r of roots) {
+      const p = path.join(r, 'playwright');
+      if (fs.existsSync(p)) return require(p);
+    }
+    console.error('playwright not resolvable: npm i -g playwright (or npm i playwright in this repo)');
+    process.exit(1);
+  }
+}
+
 function parseArgs(argv) {
   const args = {};
   for (let i = 2; i < argv.length; i++) {
@@ -56,7 +74,7 @@ function sessionDir(cfg, args) {
 // HARD RULE: select the tab by URL substring, never pages()[0] — other
 // automations share the browser (Tesla tab hijacked slot 0 on 2026-08-02).
 async function findTab(port, match) {
-  const { chromium } = require('playwright');
+  const { chromium } = requirePlaywright();
   const browser = await chromium.connectOverCDP(`http://127.0.0.1:${port}`);
   const pages = browser.contexts()[0].pages();
   const page = pages.find(p => p.url().includes(match));
@@ -79,4 +97,4 @@ async function dumpState(page, dir, label) {
   console.log('INPUTS:', JSON.stringify(inputs.filter(i => i.vis)));
 }
 
-module.exports = { PLATFORMS, parseArgs, loadConfig, platform, sessionDir, findTab, dumpState };
+module.exports = { PLATFORMS, parseArgs, loadConfig, platform, sessionDir, findTab, dumpState, requirePlaywright };

← f519a12 absorb delivery-address-skill (TK-10144): generic launch/sta  ·  back to Delivery Address Fix  ·  5x sweep 2: findTab multi-candidate match; ubereats matches 8ecbebb →