rnxsim 0.0.0 → 0.1.313
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.
- package/LICENSE +21 -0
- package/README.md +512 -0
- package/detox/colors.ts +54 -0
- package/detox/config-loader.ts +135 -0
- package/detox/element-types.ts +39 -0
- package/detox/expectations.ts +537 -0
- package/detox/gestures.ts +480 -0
- package/detox/index.ts +2118 -0
- package/detox/jest-preset.cjs +51 -0
- package/detox/jest-setup-after-env.cjs +18 -0
- package/detox/matchers.ts +30 -0
- package/detox/motion-change.cjs +109 -0
- package/detox/motion-change.d.cts +35 -0
- package/detox/navigation.ts +43 -0
- package/detox/screenshots/animated-color-test-rest-norngh.png +0 -0
- package/detox/screenshots/color-test-after-drag-norngh.png +0 -0
- package/detox/screenshots/color-test-rest-norngh.png +0 -0
- package/detox/screenshots/theme-blue-toggle.png +0 -0
- package/detox/screenshots/theme-blue.png +0 -0
- package/detox/screenshots/theme-red-toggle.png +0 -0
- package/detox/screenshots/theme-red.png +0 -0
- package/dist-cli/bin.js +15 -0
- package/dist-cli/chunks/agent-XZ2KTPCU.js +48 -0
- package/dist-cli/chunks/agent-wrapper-JJYYW2WH.js +17 -0
- package/dist-cli/chunks/app-fonts-IXRNQG6B.js +4 -0
- package/dist-cli/chunks/assert-54T5SK5F.js +49 -0
- package/dist-cli/chunks/auth-FI5UDI45.js +12 -0
- package/dist-cli/chunks/beta-JV6UKADW.js +4 -0
- package/dist-cli/chunks/camera-VL73YIKP.js +22 -0
- package/dist-cli/chunks/chunk-2D2UPBBR.js +4 -0
- package/dist-cli/chunks/chunk-2YR5BGA5.js +5 -0
- package/dist-cli/chunks/chunk-3NV2NCNX.js +4 -0
- package/dist-cli/chunks/chunk-46EUUFJ5.js +4 -0
- package/dist-cli/chunks/chunk-4NPPOV2N.js +5 -0
- package/dist-cli/chunks/chunk-5DHC6KHQ.js +7 -0
- package/dist-cli/chunks/chunk-5TEF3ET3.js +74 -0
- package/dist-cli/chunks/chunk-5TPRP5QT.js +4 -0
- package/dist-cli/chunks/chunk-5YJCOWCH.js +4 -0
- package/dist-cli/chunks/chunk-7GN3LVWB.js +4 -0
- package/dist-cli/chunks/chunk-BBULZ7CG.js +568 -0
- package/dist-cli/chunks/chunk-BTWORNNG.js +71 -0
- package/dist-cli/chunks/chunk-D4FFVGI5.js +5 -0
- package/dist-cli/chunks/chunk-DCEMHR2Y.js +4 -0
- package/dist-cli/chunks/chunk-DZS6WPUI.js +4 -0
- package/dist-cli/chunks/chunk-F5ZRSS3C.js +3 -0
- package/dist-cli/chunks/chunk-FSUYIVJ6.js +9 -0
- package/dist-cli/chunks/chunk-G2WW6L2C.js +23 -0
- package/dist-cli/chunks/chunk-GASE6UBA.js +4 -0
- package/dist-cli/chunks/chunk-GGRX24GF.js +142 -0
- package/dist-cli/chunks/chunk-HI5TFJWN.js +5 -0
- package/dist-cli/chunks/chunk-IJ5CAZZC.js +5 -0
- package/dist-cli/chunks/chunk-IJO63TDP.js +4 -0
- package/dist-cli/chunks/chunk-KTHV3RUS.js +26 -0
- package/dist-cli/chunks/chunk-LF2ZVT7O.js +6 -0
- package/dist-cli/chunks/chunk-MJRLLB4R.js +38 -0
- package/dist-cli/chunks/chunk-NFK7T35W.js +4 -0
- package/dist-cli/chunks/chunk-NMF2ZMZQ.js +15 -0
- package/dist-cli/chunks/chunk-OHAZNXLK.js +4 -0
- package/dist-cli/chunks/chunk-OVFJFXUD.js +101 -0
- package/dist-cli/chunks/chunk-OZSSI4WN.js +28 -0
- package/dist-cli/chunks/chunk-QKDWYITG.js +25 -0
- package/dist-cli/chunks/chunk-RSZWCKNT.js +30 -0
- package/dist-cli/chunks/chunk-RTN5C5RL.js +4 -0
- package/dist-cli/chunks/chunk-TIVZIMMW.js +4 -0
- package/dist-cli/chunks/chunk-TZFFR3SD.js +7 -0
- package/dist-cli/chunks/chunk-UC6U3MML.js +5 -0
- package/dist-cli/chunks/chunk-VFCMSYZK.js +6 -0
- package/dist-cli/chunks/chunk-VNQEB4L7.js +5 -0
- package/dist-cli/chunks/chunk-VZXWHRUZ.js +983 -0
- package/dist-cli/chunks/chunk-W6K4EFPH.js +107 -0
- package/dist-cli/chunks/chunk-WEXDAC74.js +4 -0
- package/dist-cli/chunks/chunk-WF3T4SVI.js +14 -0
- package/dist-cli/chunks/chunk-WINYQ44O.js +4 -0
- package/dist-cli/chunks/chunk-WMIIKMGK.js +10 -0
- package/dist-cli/chunks/chunk-WUSWBCWA.js +507 -0
- package/dist-cli/chunks/chunk-WWZIXIRD.js +4 -0
- package/dist-cli/chunks/chunk-XEVZYVIW.js +766 -0
- package/dist-cli/chunks/chunk-YDGQTMQL.js +4 -0
- package/dist-cli/chunks/chunk-YIFT42WN.js +4 -0
- package/dist-cli/chunks/chunk-ZMJD5GEC.js +125 -0
- package/dist-cli/chunks/cleanup-P27PA6JI.js +25 -0
- package/dist-cli/chunks/cli-version-WWLPBDQ7.js +4 -0
- package/dist-cli/chunks/compat-ZD65FED3.js +20 -0
- package/dist-cli/chunks/config-XMJRNM2A.js +13 -0
- package/dist-cli/chunks/control-KMIQT3QP.js +4 -0
- package/dist-cli/chunks/daemon-G2ME7NLB.js +4 -0
- package/dist-cli/chunks/debug-PT4HOP7N.js +200 -0
- package/dist-cli/chunks/desktop-S3FG72AK.js +31 -0
- package/dist-cli/chunks/detox-B3D4IFCN.js +52 -0
- package/dist-cli/chunks/device-XBNDSB2R.js +18 -0
- package/dist-cli/chunks/diagnose-HMQXJE5N.js +43 -0
- package/dist-cli/chunks/disk-cleanup-BLCZ5BSZ.js +4 -0
- package/dist-cli/chunks/drivers-LDECZGP2.js +4 -0
- package/dist-cli/chunks/film-BJGTBYZB.js +74 -0
- package/dist-cli/chunks/flow-UEQNVTU7.js +4 -0
- package/dist-cli/chunks/help-T5FYSVGB.js +4 -0
- package/dist-cli/chunks/hidden-runtime-alias-ANOYADHM.js +4 -0
- package/dist-cli/chunks/home-paths-GT3LFNOR.js +4 -0
- package/dist-cli/chunks/inspect-ZA6XF5LD.js +4 -0
- package/dist-cli/chunks/install-desktop-TIMUDHPL.js +4 -0
- package/dist-cli/chunks/login-FJ737MWG.js +28 -0
- package/dist-cli/chunks/logout-ZCNMMHMY.js +4 -0
- package/dist-cli/chunks/maestro-SZTNKLDF.js +104 -0
- package/dist-cli/chunks/maestro-generate-DCFAIZ4H.js +36 -0
- package/dist-cli/chunks/mode-GRMQCRXR.js +26 -0
- package/dist-cli/chunks/optional-demo-registry-W36EWFFB.js +4 -0
- package/dist-cli/chunks/perf-QYBAAUZG.js +48 -0
- package/dist-cli/chunks/permissions-3QCQ6VF4.js +13 -0
- package/dist-cli/chunks/record-QPPC2S4E.js +72 -0
- package/dist-cli/chunks/report-issue-7NMFP4HK.js +29 -0
- package/dist-cli/chunks/runtime-XOAXMSTU.js +4 -0
- package/dist-cli/chunks/screenshot-command-67AECJFB.js +159 -0
- package/dist-cli/chunks/screenshot-layers-ASWBYPJL.js +20 -0
- package/dist-cli/chunks/screenshots-capture-PXA3HFQK.js +42 -0
- package/dist-cli/chunks/serve-BI2NBAXG.js +44 -0
- package/dist-cli/chunks/setup-7DWPMRSB.js +32 -0
- package/dist-cli/chunks/skills-S3Y22TUA.js +50 -0
- package/dist-cli/chunks/storage-XUIMJWAJ.js +37 -0
- package/dist-cli/chunks/store-JTHEJLAZ.js +4 -0
- package/dist-cli/chunks/telemetry-ZYJGD2DB.js +4 -0
- package/dist-cli/chunks/timeline-TMPLQPSP.js +24 -0
- package/dist-cli/chunks/upgrade-7HDSIM7K.js +7 -0
- package/dist-cli/chunks/upload-GMSZPWM6.js +4 -0
- package/dist-cli/chunks/version-HOCHZ37L.js +6 -0
- package/dist-cli/chunks/web-DG3WBYD3.js +4 -0
- package/dist-cli/chunks/what-happened-XFVUTZR7.js +25 -0
- package/dist-lib/agent-daemon-client.cjs +468 -0
- package/dist-lib/agent-events.cjs +48 -0
- package/dist-lib/agent-identity.cjs +53 -0
- package/dist-lib/agent-sessions.cjs +725 -0
- package/dist-lib/attached-projects.cjs +526 -0
- package/dist-lib/auth/shared-session.cjs +195 -0
- package/dist-lib/backend-origin.cjs +70 -0
- package/dist-lib/beta.cjs +41 -0
- package/dist-lib/beta.mjs +13 -0
- package/dist-lib/bridge-constants.cjs +161 -0
- package/dist-lib/cli-constants.cjs +32 -0
- package/dist-lib/config.cjs +96 -0
- package/dist-lib/detox/index.cjs +2863 -0
- package/dist-lib/detox/jest-preset.cjs +51 -0
- package/dist-lib/dev-bundle-resolution.cjs +223 -0
- package/dist-lib/home-paths.cjs +421 -0
- package/dist-lib/host/bridge-host.cjs +5600 -0
- package/dist-lib/host/fetch-proxy-handler.cjs +373 -0
- package/dist-lib/host/fetch-proxy-overrides.cjs +63 -0
- package/dist-lib/host/fetch-proxy-overrides.mjs +37 -0
- package/dist-lib/host/websocket-proxy.cjs +214 -0
- package/dist-lib/index.cjs +513 -0
- package/dist-lib/jump-to-source-babel.cjs +93 -0
- package/dist-lib/menu.cjs +620 -0
- package/dist-lib/menu.mjs +581 -0
- package/dist-lib/metro.cjs +297 -0
- package/dist-lib/profiles.cjs +246 -0
- package/dist-lib/public-brand.cjs +39 -0
- package/dist-lib/render-mode.cjs +54 -0
- package/dist-lib/scripts/dev-server-scanner.cjs +1034 -0
- package/dist-lib/sdk.cjs +2333 -0
- package/dist-lib/sdk.mjs +2240 -0
- package/dist-lib/skills.cjs +23922 -0
- package/dist-lib/vite.cjs +358 -0
- package/package.json +189 -18
- package/scripts/dev-server-scanner.ts +941 -0
- package/scripts/optional-demo-registry.ts +113 -0
- package/scripts/postinstall.cjs +3 -0
- package/scripts/preuninstall.cjs +118 -0
- package/skills/contrast/SKILL.md +171 -0
- package/skills/rnx-debug/SKILL.md +425 -0
- package/skills/rnx-perf/SKILL.md +295 -0
- package/skills/rnx-setup/SKILL.md +160 -0
- package/skills/rnx-test/SKILL.md +292 -0
- package/skills/rnx-visual/SKILL.md +122 -0
- package/src/agent-daemon-client.ts +410 -0
- package/src/agent-events.ts +71 -0
- package/src/agent-identity.ts +23 -0
- package/src/agent-prompt.ts +71 -0
- package/src/agent-sessions.ts +573 -0
- package/src/attached-projects.ts +539 -0
- package/src/auth/shared-session.ts +204 -0
- package/src/backend-origin.ts +49 -0
- package/src/beta.ts +19 -0
- package/src/bridge-constants.ts +171 -0
- package/src/browser-cache.ts +16 -0
- package/src/cli-constants.ts +1 -0
- package/src/cli-version.ts +32 -0
- package/src/codex-client.ts +215 -0
- package/src/config.ts +134 -0
- package/src/dev-bundle-resolution.ts +236 -0
- package/src/disk-cleanup.ts +466 -0
- package/src/home-paths.ts +552 -0
- package/src/host/agent-host.ts +666 -0
- package/src/host/bridge-host.ts +2626 -0
- package/src/host/fetch-proxy-handler.ts +397 -0
- package/src/host/fetch-proxy-overrides.ts +51 -0
- package/src/host/open-url.ts +89 -0
- package/src/host/websocket-proxy.ts +210 -0
- package/src/index.ts +12 -705
- package/src/jump-to-source-babel.ts +135 -0
- package/src/menu.ts +734 -0
- package/src/metro-plugin.ts +139 -0
- package/src/native-dev-bundle-url.ts +96 -0
- package/src/native-seam-manifest.ts +341 -0
- package/src/plist.ts +27 -0
- package/src/poll-until.ts +92 -0
- package/src/profiles.ts +179 -0
- package/src/public-brand.ts +9 -0
- package/src/render-mode.ts +27 -0
- package/src/runtime-assets.ts +228 -0
- package/src/runtime-delivery.ts +54 -0
- package/src/screenshots/compose.ts +422 -0
- package/src/screenshots/frame-compose.ts +454 -0
- package/src/screenshots/orchestrate.ts +256 -0
- package/src/screenshots/org-deck.ts +91 -0
- package/src/screenshots/registry.ts +58 -0
- package/src/screenshots/schema.ts +364 -0
- package/src/sdk.ts +7 -0
- package/src/settings-bundle.ts +418 -0
- package/src/skills/builtin/a11y-review.ts +132 -0
- package/src/skills/builtin/compat-check.ts +71 -0
- package/src/skills/builtin/maestro-test.ts +121 -0
- package/src/skills/builtin/perf-profile.ts +90 -0
- package/src/skills/builtin/screenshot-all.ts +52 -0
- package/src/skills/builtin/visual-diff.ts +100 -0
- package/src/skills/registry.ts +107 -0
- package/src/skills/types.ts +41 -0
- package/src/team-machine-prompt.ts +73 -0
- package/src/vite-plugin-one.ts +190 -0
- package/src/vite-plugin.ts +1750 -0
- package/src/worklets-babel.ts +134 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! rnx v0.1.313 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
import { createRequire as __sootsimCreateRequire } from 'node:module'
|
|
3
|
+
var require = __sootsimCreateRequire(import.meta.url)
|
|
4
|
+
var g=Object.create;var e=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var n=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports),o=(a,b)=>{for(var c in b)e(a,c,{get:b[c],enumerable:!0})},l=(a,b,c,f)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of i(b))!k.call(a,d)&&d!==c&&e(a,d,{get:()=>b[d],enumerable:!(f=h(b,d))||f.enumerable});return a};var p=(a,b,c)=>(c=a!=null?g(j(a)):{},l(b||!a||!a.__esModule?e(c,"default",{value:a,enumerable:!0}):c,a));export{m as a,n as b,o as c,p as d};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! rnx v0.1.313 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
import { createRequire as __sootsimCreateRequire } from 'node:module'
|
|
3
|
+
var require = __sootsimCreateRequire(import.meta.url)
|
|
4
|
+
import{a as d}from"./chunk-TIVZIMMW.js";import{a as s}from"./chunk-VNQEB4L7.js";import{a as e}from"./chunk-UC6U3MML.js";import{a as n}from"./chunk-4NPPOV2N.js";import{c as m,d as p,e as u}from"./chunk-ZMJD5GEC.js";import{a}from"./chunk-3NV2NCNX.js";import{a as i}from"./chunk-2D2UPBBR.js";import{a as f,c}from"./chunk-46EUUFJ5.js";function g(){return`${i.commandName} CLI v${a()} \xB7 ${d().primary}`}function E(){let r=p({bridgePort:7668,defaultShellUrl:n},e()),o=`
|
|
5
|
+
${c}
|
|
6
|
+
`;console.log(`${g()}
|
|
7
|
+
${o}${r}
|
|
8
|
+
`),s("clean-uninstall")}function L(r){let o=m(r,{bridgePort:7668,defaultShellUrl:n},e());return o?(console.log(`${o}
|
|
9
|
+
`),!0):!1}function U(r,o={}){let l=u(r,{bridgePort:7668,defaultShellUrl:n},o);if(!l){console.log(`unknown command: ${r}`);return}console.log(`${l}
|
|
10
|
+
`)}export{E as a,L as b,U as c};
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/*! rnx v0.1.313 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
import { createRequire as __sootsimCreateRequire } from 'node:module'
|
|
3
|
+
var require = __sootsimCreateRequire(import.meta.url)
|
|
4
|
+
import{a as y,b as M}from"./chunk-5DHC6KHQ.js";import{a as A}from"./chunk-RTN5C5RL.js";import{b as C}from"./chunk-IJ5CAZZC.js";import{G as T,o as E,q as b}from"./chunk-FSUYIVJ6.js";import v from"fs";import S from"path";var h="default",H="profiles.json",u=1;function d(e){let t=e.trim();if(!t)throw new Error("profile id is required");if(!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(t))throw new Error("profile ids must start with a letter or number and contain only letters, numbers, dot, dash, or underscore");if(t==="."||t==="..")throw new Error(`invalid profile id: ${t}`);return t}function P(){return S.join(b(),H)}function z(e){return`sootsim-profile-${d(e)}`}function J(e){return S.join(E(),"Partitions",z(e))}function x(e){return S.join(b(),"playwright",d(e))}function k(){try{let e=JSON.parse(v.readFileSync(P(),"utf8"));if(!e||e.version!==u)return{version:u,profiles:[]};let t=Array.isArray(e.profiles)?e.profiles.filter(r=>!!r&&typeof r.id=="string"&&typeof r.createdAt=="string"&&typeof r.updatedAt=="string").map(r=>({id:d(r.id),createdAt:r.createdAt,updatedAt:r.updatedAt})):[];return{version:u,profiles:t}}catch{return{version:u,profiles:[]}}}function R(e){return[...e].sort((t,r)=>t.id===h?-1:r.id===h?1:t.id.localeCompare(r.id))}function O(e){if(e.profiles.some(r=>r.id===h))return{...e,profiles:R(e.profiles)};let t=new Date().toISOString();return{version:u,profiles:R([{id:h,createdAt:t,updatedAt:t},...e.profiles])}}function D(e){T();let t=O(e),r=`${P()}.tmp`;return v.writeFileSync(r,`${JSON.stringify(t,null,2)}
|
|
5
|
+
`,"utf8"),v.renameSync(r,P()),t}function K(){return D(k()).profiles}function Y(e){let t=d(e);return K().find(r=>r.id===t)??null}function L(e=h){let t=d(e),r=Y(t);return r||V(t)}function V(e){let t=d(e),r=O(k());if(r.profiles.some(i=>i.id===t))throw new Error(`profile already exists: ${t}`);let o=new Date().toISOString(),n={id:t,createdAt:o,updatedAt:o};return D({version:u,profiles:[...r.profiles,n]}),n}function ve(e){let t=d(e);if(t===h)throw new Error("the default profile cannot be deleted; clear it instead");let r=O(k()),o=r.profiles.find(n=>n.id===t);if(!o)throw new Error(`profile not found: ${t}`);return D({version:u,profiles:r.profiles.filter(n=>n.id!==t)}),X(t),o}function X(e){let t=d(e);for(let r of[J(t),x(t)])try{v.rmSync(r,{recursive:!0,force:!0})}catch{}}function Z(){let e=y();return e?{available:!0,reason:null,detail:`${e.kind} @ ${e.path}`}:{available:!1,reason:"rnxsim desktop app not installed (run `rnxsim desktop install`)"}}async function Q(e){let t=y();if(!t)return{launched:!1,message:"rnxsim desktop app not installed"};try{let r=await M(e.url,t,{device:e.device,profileId:e.profileId,ephemeralProfile:e.ephemeralProfile,ownerPid:e.ownerPid});return r.launched?{launched:!0,message:e.url?`electron launched via ${r.via} \u2192 ${e.url}`:`electron launched via ${r.via}`,target:r.target,attachUrl:e.url}:{launched:!1,message:"desktop companion failed to start"}}catch(r){return{launched:!1,message:`electron launch failed: ${r instanceof Error?r.message:String(r)}`}}}var W={id:"electron",name:"electron",description:"rnxsim desktop companion app (native window, menu bar)",kind:"native",availability:Z,launch:Q};import{spawn as ie}from"child_process";import{closeSync as se,mkdtempSync as ae,openSync as le,readFileSync as ce}from"fs";import{tmpdir as G}from"os";import{join as B}from"path";import{spawnSync as $}from"node:child_process";import{existsSync as F,readFileSync as ee}from"node:fs";import{createRequire as re}from"node:module";import{dirname as te,join as oe}from"node:path";var ne=`
|
|
6
|
+
const { existsSync } = require('node:fs');
|
|
7
|
+
const modulePath = process.env.SOOTSIM_PW_MODULE;
|
|
8
|
+
try {
|
|
9
|
+
const playwright = require(modulePath);
|
|
10
|
+
const browser = playwright && playwright.chromium;
|
|
11
|
+
if (!browser || typeof browser.executablePath !== 'function') {
|
|
12
|
+
throw new Error('resolved package does not expose browser "chromium"');
|
|
13
|
+
}
|
|
14
|
+
const executablePath = browser.executablePath();
|
|
15
|
+
process.stdout.write(JSON.stringify({ executablePath, exists: existsSync(executablePath) }));
|
|
16
|
+
} catch (error) {
|
|
17
|
+
process.stderr.write(String((error && error.stack) || error));
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
`;function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function I(){let e=[`${process.cwd()}/`];process.argv[1]&&e.push(process.argv[1]);for(let t of e)try{let r=re(t);for(let o of["playwright","playwright-chromium","playwright-core"])try{let n=r.resolve(o),i=r.resolve(`${o}/package.json`),a=JSON.parse(ee(i,"utf8"));if(!_(a)||typeof a.version!="string")continue;let l=a.bin,s=null;if(typeof l=="string")s=l;else if(_(l)){let f=l.playwright??l["playwright-core"],g=Object.values(l).find(c=>typeof c=="string");s=typeof f=="string"?f:typeof g=="string"?g:null}if(!s)continue;let p=oe(te(i),s);if(!F(p))continue;return{spec:o,modulePath:n,cliPath:p,version:a.version}}catch{}}catch{}return null}function N(e,t){let r=$(process.execPath,["-e",ne],{env:{...t,SOOTSIM_PW_MODULE:e.modulePath},encoding:"utf8",timeout:3e4});if(r.status!==0){let o=(r.stderr||r.error?.message||"browser probe failed").trim();return{ok:!1,message:`could not inspect ${e.spec}@${e.version} chromium: ${o}`}}try{let o=JSON.parse(r.stdout);if(!_(o)||typeof o.executablePath!="string"||typeof o.exists!="boolean")throw new Error("probe returned an invalid result");return{ok:!0,executablePath:o.executablePath,exists:o.exists&&F(o.executablePath)}}catch(o){return{ok:!1,message:`could not inspect ${e.spec}@${e.version} chromium: ${o instanceof Error?o.message:String(o)}`}}}function U(e,t=process.env){let r=N(e,t);if(!r.ok)return r;if(r.exists)return{ok:!0,executablePath:r.executablePath,installed:!1};let o=$(process.execPath,[e.cliPath,"install","chromium"],{env:t,encoding:"utf8",timeout:10*6e4});if(o.status!==0){let i=(o.stderr||o.stdout||o.error?.message||"browser install failed").trim(),a=i.length<=4e3?i:i.slice(-4e3);return{ok:!1,message:`${e.spec}@${e.version} requires chromium at ${r.executablePath}, but its browser install failed${a?`:
|
|
21
|
+
${a}`:""}`}}let n=N(e,t);return n.ok?n.exists?{ok:!0,executablePath:n.executablePath,installed:!0}:{ok:!1,message:`${e.spec}@${e.version} browser install completed, but its required chromium executable is still missing at ${n.executablePath}`}:n}var de=`
|
|
22
|
+
const modulePath = process.env.SOOTSIM_PW_MODULE;
|
|
23
|
+
const url = process.env.SOOTSIM_PW_URL;
|
|
24
|
+
// the WS bridge port the sim page must register with, injected below as
|
|
25
|
+
// window.__sootsimBridgePort so the page skips its shell-port heuristic (which
|
|
26
|
+
// assumes the default offset and breaks when the dev bridge drifted).
|
|
27
|
+
const bridgePort = process.env.SOOTSIM_PW_BRIDGE_PORT || '';
|
|
28
|
+
const headless = process.env.SOOTSIM_PW_HEADLESS === '1';
|
|
29
|
+
const callerUserDataDir = process.env.SOOTSIM_PW_USERDATADIR || '';
|
|
30
|
+
// pid of the session that launched us (its topmost non-init ancestor). when
|
|
31
|
+
// that process exits we tear Chrome down \u2014 see startOwnerWatch below. it is a
|
|
32
|
+
// required lifetime bound: an invalid value aborts before Chrome launches.
|
|
33
|
+
// SOOTSIM_PW_OWNER_POLL_MS is a test-only override of the 5s poll interval;
|
|
34
|
+
// production never sets it.
|
|
35
|
+
const ownerPid = Number(process.env.SOOTSIM_PW_OWNER_PID || 0);
|
|
36
|
+
const ownerPollMs = Number(process.env.SOOTSIM_PW_OWNER_POLL_MS || 5000);
|
|
37
|
+
// optional CDP port \u2014 exposes Chrome's remote-debugging endpoint so a
|
|
38
|
+
// bridge-driven sim can also be cpu-profiled (sootsim perf cpu --cdp-port).
|
|
39
|
+
// playwright keeps its own pipe connection; the port is an additional endpoint.
|
|
40
|
+
const cdpPort = process.env.SOOTSIM_PW_CDP_PORT || '';
|
|
41
|
+
// extra chromium launch args, space-separated. a linux GPU runner injects
|
|
42
|
+
// '--use-angle=vulkan --enable-features=Vulkan' here so chrome binds the
|
|
43
|
+
// real GPU instead of silently falling back to swiftshader software
|
|
44
|
+
// rendering (which pegs cores and produces ~1fps canvas capture).
|
|
45
|
+
const extraChromeArgs = (process.env.SOOTSIM_PW_CHROME_ARGS || '')
|
|
46
|
+
.split(' ')
|
|
47
|
+
.filter(Boolean);
|
|
48
|
+
// Local CanvasKit work must never fall back to Playwright's software
|
|
49
|
+
// renderer. CI may use the bundled browser for non-interactive coverage, but
|
|
50
|
+
// local test drives fail closed unless the hardware-backed test browser is
|
|
51
|
+
// proven after launch.
|
|
52
|
+
const hardwareGpuRequired = process.env.CI !== '1' && process.env.CI !== 'true';
|
|
53
|
+
const softwareRendererPattern = /swiftshader|software(?: rasterizer)?|llvmpipe|lavapipe|softpipe/i;
|
|
54
|
+
// page viewport as '<w>x<h>'. the caller sizes it from the device profile;
|
|
55
|
+
// the fallback is phone-shaped because the page hosts a phone sim \u2014 the
|
|
56
|
+
// playwright default (1280x720 desktop) letterboxes the device frame.
|
|
57
|
+
const viewportSpec = /^(\\d+)x(\\d+)$/.exec(process.env.SOOTSIM_PW_VIEWPORT || '');
|
|
58
|
+
const viewport = viewportSpec
|
|
59
|
+
? { width: Number(viewportSpec[1]), height: Number(viewportSpec[2]) }
|
|
60
|
+
: { width: 600, height: 900 };
|
|
61
|
+
// device pixels per css pixel. playwright's default is 1, which makes the
|
|
62
|
+
// engine allocate its canvas backing store at HALF the resolution a normal
|
|
63
|
+
// retina-mac chrome would (dpr 2) \u2014 the sim looks visibly soft. default to 2
|
|
64
|
+
// so a driver-launched sim matches what the user sees in their own browser.
|
|
65
|
+
const deviceScaleFactor = Number(process.env.SOOTSIM_PW_DSF || 2);
|
|
66
|
+
const closeTimeoutMs = Number(process.env.SOOTSIM_PW_CLOSE_TIMEOUT_MS || 2500);
|
|
67
|
+
const connectAckFile = process.env.SOOTSIM_PW_CONNECTED_ACK_FILE || '';
|
|
68
|
+
const disposableBrowserCacheDirs = new Set(${JSON.stringify(A)});
|
|
69
|
+
const { existsSync, mkdtempSync, readdirSync, rmSync, unlinkSync } = require('fs');
|
|
70
|
+
const { execSync } = require('child_process');
|
|
71
|
+
const { tmpdir } = require('os');
|
|
72
|
+
const { join } = require('path');
|
|
73
|
+
// chrome tree reaper \u2014 playwright's browser.close() and even SIGKILLing the
|
|
74
|
+
// root chrome process do NOT reliably take down the helper tree (gpu, renderer,
|
|
75
|
+
// network/storage utilities). they reparent to launchd/init and survive, each
|
|
76
|
+
// one busy enough to peg CPU at 100%+. close() only reaches the root.
|
|
77
|
+
//
|
|
78
|
+
// the prior approach was \`pgrep -f ms-playwright/[c]hromium\`. it never matched
|
|
79
|
+
// system Chrome, so the reaper was a no-op in the common case and every
|
|
80
|
+
// aborted/closed \`sootsim open\` leaked a renderer + gpu helper burning 100%+
|
|
81
|
+
// CPU until manually killed (multiple incidents 2026-06).
|
|
82
|
+
//
|
|
83
|
+
// fix: identify our chrome tree by its UNIQUE user-data-dir. every helper a
|
|
84
|
+
// chrome root spawns inherits \`--user-data-dir=<dir>\` in its cmdline, so
|
|
85
|
+
// \`pgrep -f <profileDir>\` finds exactly the tree we launched and nothing else
|
|
86
|
+
// \u2014 Chrome for Testing and bundled playwright chromium alike. as a side benefit we
|
|
87
|
+
// no longer need the launch / launchPersistentContext fork: we ALWAYS use a
|
|
88
|
+
// profile dir (mkdtemp'd if the caller didn't pass one, then removed at exit).
|
|
89
|
+
const reapEnabled = process.platform !== 'win32';
|
|
90
|
+
let profileDir = callerUserDataDir;
|
|
91
|
+
let ephemeralProfile = false;
|
|
92
|
+
if (!profileDir) {
|
|
93
|
+
profileDir = mkdtempSync(join(tmpdir(), 'sootsim-playwright-host-'));
|
|
94
|
+
ephemeralProfile = true;
|
|
95
|
+
}
|
|
96
|
+
// browser HTTP caches are acceleration data, not profile identity. give each
|
|
97
|
+
// host a bounded temporary cache so persistent named profiles retain cookies
|
|
98
|
+
// and storage without multiplying a private cache for every profile.
|
|
99
|
+
const diskCacheDir = mkdtempSync(join(tmpdir(), 'sootsim-playwright-cache-'));
|
|
100
|
+
const chromePidsByProfile = () => {
|
|
101
|
+
if (!reapEnabled) return [];
|
|
102
|
+
try {
|
|
103
|
+
return execSync('pgrep -f ' + profileDir + ' || true', { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
104
|
+
.toString().split('\\n').filter(Boolean).map((p) => Number(p))
|
|
105
|
+
.filter((p) => p && p !== process.pid);
|
|
106
|
+
} catch { return []; }
|
|
107
|
+
};
|
|
108
|
+
const chromeCommandsByProfile = () => {
|
|
109
|
+
if (!reapEnabled) return [];
|
|
110
|
+
const pids = chromePidsByProfile();
|
|
111
|
+
if (pids.length === 0) return [];
|
|
112
|
+
try {
|
|
113
|
+
return execSync('ps -p ' + pids.join(',') + ' -o command=', {
|
|
114
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
115
|
+
}).toString().split('\\n').filter(Boolean);
|
|
116
|
+
} catch { return []; }
|
|
117
|
+
};
|
|
118
|
+
const assertNoUnsafeSwiftShaderFlag = () => {
|
|
119
|
+
if (!hardwareGpuRequired) return;
|
|
120
|
+
const unsafe = chromeCommandsByProfile().find((command) =>
|
|
121
|
+
command.includes('--enable-unsafe-swiftshader') ||
|
|
122
|
+
/--use-angle=(?:swiftshader|swiftshader-webgl)(?:\\s|$)/i.test(command)
|
|
123
|
+
);
|
|
124
|
+
if (unsafe) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
'[playwright-driver] refused software-rendering Chrome: launched process contains a SwiftShader flag'
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const killTree = (pid) => {
|
|
131
|
+
let kids = [];
|
|
132
|
+
try {
|
|
133
|
+
kids = execSync('pgrep -P ' + pid + ' || true', { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
134
|
+
.toString().split('\\n').filter(Boolean);
|
|
135
|
+
} catch {}
|
|
136
|
+
for (const k of kids) killTree(Number(k));
|
|
137
|
+
try { process.kill(pid, 'SIGKILL'); } catch {}
|
|
138
|
+
};
|
|
139
|
+
const reapChrome = () => { for (const pid of chromePidsByProfile()) killTree(pid); };
|
|
140
|
+
const removeDisposableCaches = (root) => {
|
|
141
|
+
let children = [];
|
|
142
|
+
try { children = readdirSync(root, { withFileTypes: true }); } catch { return; }
|
|
143
|
+
for (const child of children) {
|
|
144
|
+
if (!child.isDirectory() || child.isSymbolicLink()) continue;
|
|
145
|
+
const childPath = join(root, child.name);
|
|
146
|
+
if (disposableBrowserCacheDirs.has(child.name)) {
|
|
147
|
+
try { rmSync(childPath, { recursive: true, force: true }); } catch {}
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
removeDisposableCaches(childPath);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const cleanupProfile = () => {
|
|
154
|
+
try { rmSync(diskCacheDir, { recursive: true, force: true }); } catch {}
|
|
155
|
+
if (ephemeralProfile) {
|
|
156
|
+
try { rmSync(profileDir, { recursive: true, force: true }); } catch {}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
removeDisposableCaches(profileDir);
|
|
160
|
+
};
|
|
161
|
+
(async () => {
|
|
162
|
+
const pw = require(modulePath);
|
|
163
|
+
let context;
|
|
164
|
+
let keepAlive = null;
|
|
165
|
+
let connectTimer = null;
|
|
166
|
+
let connectAckPoll = null;
|
|
167
|
+
let ownerWatch = null;
|
|
168
|
+
let connected = false;
|
|
169
|
+
let shuttingDown = false;
|
|
170
|
+
const clearConnectTimer = () => {
|
|
171
|
+
if (connectTimer) {
|
|
172
|
+
clearTimeout(connectTimer);
|
|
173
|
+
connectTimer = null;
|
|
174
|
+
}
|
|
175
|
+
if (connectAckPoll) {
|
|
176
|
+
clearInterval(connectAckPoll);
|
|
177
|
+
connectAckPoll = null;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const markConnected = () => {
|
|
181
|
+
connected = true;
|
|
182
|
+
clearConnectTimer();
|
|
183
|
+
};
|
|
184
|
+
const ackFileExists = () => {
|
|
185
|
+
if (!connectAckFile) return false;
|
|
186
|
+
try { return existsSync(connectAckFile); } catch { return false; }
|
|
187
|
+
};
|
|
188
|
+
const bounded = async (label, work, timeoutMs) => {
|
|
189
|
+
let timer = null;
|
|
190
|
+
try {
|
|
191
|
+
const timeout = new Promise((resolve) => {
|
|
192
|
+
timer = setTimeout(() => resolve({ timedOut: true }), timeoutMs);
|
|
193
|
+
});
|
|
194
|
+
if (typeof timer.unref === 'function') timer.unref();
|
|
195
|
+
const result = await Promise.race([
|
|
196
|
+
Promise.resolve().then(work).then(
|
|
197
|
+
() => ({ timedOut: false }),
|
|
198
|
+
(error) => ({ timedOut: false, error }),
|
|
199
|
+
),
|
|
200
|
+
timeout,
|
|
201
|
+
]);
|
|
202
|
+
if (result && result.timedOut) {
|
|
203
|
+
process.stderr.write('[shutdown-timeout] ' + label + ' exceeded ' + timeoutMs + 'ms\\n');
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (result && result.error) {
|
|
207
|
+
process.stderr.write('[shutdown-error] ' + label + ': ' + String((result.error && result.error.message) || result.error) + '\\n');
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return true;
|
|
211
|
+
} finally {
|
|
212
|
+
if (timer) clearTimeout(timer);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const browserProcess = () => {
|
|
216
|
+
if (context && typeof context.browser === 'function') {
|
|
217
|
+
try {
|
|
218
|
+
const b = context.browser();
|
|
219
|
+
if (b && typeof b.process === 'function') return b.process();
|
|
220
|
+
} catch {}
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
};
|
|
224
|
+
const processIsAlive = (proc) => {
|
|
225
|
+
if (!proc || !proc.pid) return false;
|
|
226
|
+
try {
|
|
227
|
+
process.kill(proc.pid, 0);
|
|
228
|
+
return true;
|
|
229
|
+
} catch (err) {
|
|
230
|
+
return err && err.code === 'EPERM';
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
const terminateBrowserProcess = async () => {
|
|
234
|
+
const proc = browserProcess();
|
|
235
|
+
if (!proc || !proc.pid || !processIsAlive(proc)) return;
|
|
236
|
+
try { proc.kill('SIGTERM'); } catch {}
|
|
237
|
+
await bounded('browser process exit after SIGTERM', async () => {
|
|
238
|
+
while (processIsAlive(proc)) {
|
|
239
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
240
|
+
}
|
|
241
|
+
}, 600);
|
|
242
|
+
if (!processIsAlive(proc)) return;
|
|
243
|
+
try { proc.kill('SIGKILL'); } catch {}
|
|
244
|
+
};
|
|
245
|
+
const shutdown = async (code = 0) => {
|
|
246
|
+
if (shuttingDown) return;
|
|
247
|
+
shuttingDown = true;
|
|
248
|
+
clearConnectTimer();
|
|
249
|
+
if (keepAlive) clearInterval(keepAlive);
|
|
250
|
+
if (ownerWatch) clearInterval(ownerWatch);
|
|
251
|
+
const timeoutMs = Number.isFinite(closeTimeoutMs) && closeTimeoutMs > 0 ? closeTimeoutMs : 2500;
|
|
252
|
+
if (context) await bounded('context.close', () => context.close(), timeoutMs);
|
|
253
|
+
await terminateBrowserProcess();
|
|
254
|
+
// close() + root-SIGKILL above handle the graceful case; the helper tree
|
|
255
|
+
// (gpu/renderer/utilities) reparents and survives every one of those, so
|
|
256
|
+
// we always sweep by our unique profile dir as the load-bearing teardown.
|
|
257
|
+
reapChrome();
|
|
258
|
+
cleanupProfile();
|
|
259
|
+
if (connectAckFile) {
|
|
260
|
+
try { unlinkSync(connectAckFile); } catch {}
|
|
261
|
+
}
|
|
262
|
+
process.exit(code);
|
|
263
|
+
};
|
|
264
|
+
process.once('SIGTERM', () => { void shutdown(0); });
|
|
265
|
+
process.once('SIGINT', () => { void shutdown(0); });
|
|
266
|
+
// the launch-failure path at the bottom of this script exits without going
|
|
267
|
+
// through shutdown(); the exit hook (sync sweep) still reaps the tree.
|
|
268
|
+
process.on('exit', () => { reapChrome(); cleanupProfile(); });
|
|
269
|
+
// owner-liveness watchdog \u2014 the load-bearing fix for leaked Chrome hosts.
|
|
270
|
+
// we are spawned detached + unref'd so \`sootsim open\` returns immediately,
|
|
271
|
+
// which means nothing in the OS process tree ties Chrome's lifetime to the
|
|
272
|
+
// session that asked for it. once the sim connects, the connect-timeout
|
|
273
|
+
// safety net is cleared, so absent an explicit \`sootsim close\` (or the
|
|
274
|
+
// daemon's idle reaper closing the sim socket) the host would hold Chrome
|
|
275
|
+
// open forever after its owner exits. poll the owning session's pid and tear
|
|
276
|
+
// down when it's gone. ESRCH (kill throws) = owner exited; EPERM = alive but
|
|
277
|
+
// not signalable by us, which still counts as alive.
|
|
278
|
+
const startOwnerWatch = () => {
|
|
279
|
+
if (!Number.isInteger(ownerPid) || ownerPid <= 1) {
|
|
280
|
+
throw new Error('[playwright-driver] missing valid owning process; refusing unsupervised browser host');
|
|
281
|
+
}
|
|
282
|
+
const intervalMs = Number.isFinite(ownerPollMs) && ownerPollMs > 0 ? ownerPollMs : 5000;
|
|
283
|
+
ownerWatch = setInterval(() => {
|
|
284
|
+
try {
|
|
285
|
+
process.kill(ownerPid, 0);
|
|
286
|
+
} catch (err) {
|
|
287
|
+
if (err && err.code === 'EPERM') return;
|
|
288
|
+
process.stderr.write('[owner-gone] owning process ' + ownerPid + ' exited; closing playwright host\\n');
|
|
289
|
+
void shutdown(0);
|
|
290
|
+
}
|
|
291
|
+
}, intervalMs);
|
|
292
|
+
if (typeof ownerWatch.unref === 'function') ownerWatch.unref();
|
|
293
|
+
};
|
|
294
|
+
startOwnerWatch();
|
|
295
|
+
// Local rendering uses Playwright's full Chrome for Testing app. On macOS its
|
|
296
|
+
// com.google.chrome.for.testing identity cannot intercept open/quit events for
|
|
297
|
+
// the user's com.google.Chrome browser. CI may use chromium_headless_shell;
|
|
298
|
+
// local rendering fails closed because that shell has no GPU and silently
|
|
299
|
+
// chooses SwiftShader. NOTE: this is NOT enough to make \`sootsim perf cpu\`
|
|
300
|
+
// work \u2014 that profiles the tenant *worker*, and the JS Self-Profiler API
|
|
301
|
+
// cannot be constructed in a dedicated worker (see
|
|
302
|
+
// worker-handlers/cpu-profile.ts). cpu-profile needs a CDP-based profiler
|
|
303
|
+
// instead.
|
|
304
|
+
if (
|
|
305
|
+
hardwareGpuRequired &&
|
|
306
|
+
extraChromeArgs.some((arg) =>
|
|
307
|
+
arg === '--enable-unsafe-swiftshader' ||
|
|
308
|
+
/^--use-angle=(?:swiftshader|swiftshader-webgl)$/i.test(arg)
|
|
309
|
+
)
|
|
310
|
+
) {
|
|
311
|
+
throw new Error('[playwright-driver] refused SwiftShader launch arguments');
|
|
312
|
+
}
|
|
313
|
+
// one browser path per environment: the full, separately identified test app
|
|
314
|
+
// locally; chromium_headless_shell on CI. never launch a branded user browser.
|
|
315
|
+
const channelsToTry = hardwareGpuRequired ? ['chromium'] : [null];
|
|
316
|
+
const launchWith = async (channel) => {
|
|
317
|
+
const opts = channel
|
|
318
|
+
? { headless, channel, viewport, deviceScaleFactor }
|
|
319
|
+
: { headless, viewport, deviceScaleFactor };
|
|
320
|
+
// playwright injects --force-color-profile=srgb by default, which reads
|
|
321
|
+
// visibly washed-out next to a normal chrome window on a wide-gamut mac
|
|
322
|
+
// display. strip it so driver-launched sims color-match the user's own
|
|
323
|
+
// browser (real incident 2026-07-09: "low res and whitewashed" sim).
|
|
324
|
+
opts.ignoreDefaultArgs = ['--force-color-profile=srgb'];
|
|
325
|
+
// headless chromium backgrounds/occludes the renderer and throttles rAF +
|
|
326
|
+
// timers to ~1fps, which silently starves combined/video frame capture
|
|
327
|
+
// (was 47 frames over 63s -> frozen-looking mp4). keep the render loop at
|
|
328
|
+
// full rate so the recorder captures real motion. document.hidden stays
|
|
329
|
+
// false in headless, so assertTabVisibleForCapture never caught this \u2014 it
|
|
330
|
+
// has to be fixed at the launch flags.
|
|
331
|
+
opts.args = [
|
|
332
|
+
// the compositor renders through skia graphite on webgpu, so a launch
|
|
333
|
+
// without navigator.gpu boots to a fatal instead of a sim.
|
|
334
|
+
'--enable-unsafe-webgpu',
|
|
335
|
+
'--disk-cache-dir=' + diskCacheDir,
|
|
336
|
+
'--disk-cache-size=67108864',
|
|
337
|
+
'--disable-background-timer-throttling',
|
|
338
|
+
'--disable-backgrounding-occluded-windows',
|
|
339
|
+
'--disable-renderer-backgrounding',
|
|
340
|
+
];
|
|
341
|
+
if (channel) {
|
|
342
|
+
// the full test browser can bind the real platform GPU \u2014 force the native
|
|
343
|
+
// ANGLE backend and strip playwright's --enable-unsafe-swiftshader
|
|
344
|
+
// default arg. without both, headless chrome silently falls back to
|
|
345
|
+
// swiftshader software rendering for the CanvasKit/WebGL canvas and
|
|
346
|
+
// pegs every core. SOOTSIM_PW_CHROME_ARGS is appended later, so an
|
|
347
|
+
// env-injected --use-angle=... still overrides (last flag wins).
|
|
348
|
+
const angle = process.platform === 'darwin' ? 'metal'
|
|
349
|
+
: process.platform === 'linux' ? 'vulkan' : 'default';
|
|
350
|
+
opts.args.unshift(
|
|
351
|
+
'--use-angle=' + angle,
|
|
352
|
+
'--enable-gpu',
|
|
353
|
+
'--enable-gpu-rasterization',
|
|
354
|
+
'--enable-zero-copy',
|
|
355
|
+
'--ignore-gpu-blocklist',
|
|
356
|
+
);
|
|
357
|
+
opts.ignoreDefaultArgs.push('--enable-unsafe-swiftshader');
|
|
358
|
+
} else {
|
|
359
|
+
// playwright's bundled software chromium exposes no navigator.gpu until
|
|
360
|
+
// Vulkan is named explicitly, and webgpu is the only backend there is.
|
|
361
|
+
opts.args.push('--enable-features=Vulkan');
|
|
362
|
+
}
|
|
363
|
+
if (cdpPort) opts.args.push('--remote-debugging-port=' + cdpPort);
|
|
364
|
+
if (extraChromeArgs.length) opts.args.push(...extraChromeArgs);
|
|
365
|
+
// headed: size the OS window to the (phone-shaped) viewport too, plus
|
|
366
|
+
// room for chrome's own toolbar, so the window isn't desktop-shaped
|
|
367
|
+
// around a letterboxed page.
|
|
368
|
+
if (!headless) opts.args.push('--window-size=' + viewport.width + ',' + (viewport.height + 88));
|
|
369
|
+
// ALWAYS persistent: every chrome process inherits --user-data-dir=<dir>
|
|
370
|
+
// in its cmdline, which is how reapChrome() finds the whole tree (root +
|
|
371
|
+
// helpers) on shutdown. without a unique dir there is no way to attribute
|
|
372
|
+
// an orphaned helper back to us, which is the leak we just fixed.
|
|
373
|
+
return await pw.chromium.launchPersistentContext(profileDir, opts);
|
|
374
|
+
};
|
|
375
|
+
let launchErr = null;
|
|
376
|
+
let launchedChannel = null;
|
|
377
|
+
for (const channel of channelsToTry) {
|
|
378
|
+
try {
|
|
379
|
+
context = await launchWith(channel);
|
|
380
|
+
launchedChannel = channel || 'chromium';
|
|
381
|
+
launchErr = null;
|
|
382
|
+
break;
|
|
383
|
+
} catch (err) {
|
|
384
|
+
launchErr = err;
|
|
385
|
+
const msg = err && err.message ? String(err.message) : '';
|
|
386
|
+
const isMissingChannel =
|
|
387
|
+
/not found at/i.test(msg) ||
|
|
388
|
+
/not installed/i.test(msg) ||
|
|
389
|
+
/Chromium distribution/i.test(msg);
|
|
390
|
+
if (!isMissingChannel) throw err; // unexpected failure: bubble up
|
|
391
|
+
if (channel) {
|
|
392
|
+
const next = hardwareGpuRequired
|
|
393
|
+
? '; bundled Chromium is disabled for local GPU work\\n'
|
|
394
|
+
: ', falling back to bundled chromium\\n';
|
|
395
|
+
process.stderr.write('[playwright-driver] channel "' + channel + '" not available' + next);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (launchErr) throw launchErr;
|
|
400
|
+
if (launchedChannel) {
|
|
401
|
+
process.stderr.write('[playwright-driver] launched ' + launchedChannel + '\\n');
|
|
402
|
+
}
|
|
403
|
+
// grant camera up front so the sim's Camera app reaches the host webcam
|
|
404
|
+
// through getUserMedia, mirroring a real iOS simulator where the camera just
|
|
405
|
+
// works. without this the unhandled chrome permission prompt auto-denies and
|
|
406
|
+
// CameraApp renders its "Camera Access Required" placeholder.
|
|
407
|
+
await context.grantPermissions(['camera']);
|
|
408
|
+
const hostMeta = {
|
|
409
|
+
sootsimHostDriver: 'playwright',
|
|
410
|
+
sootsimHostPid: process.pid,
|
|
411
|
+
sootsimHostOwnerPid: ownerPid,
|
|
412
|
+
sootsimHostStartedAt: Date.now(),
|
|
413
|
+
};
|
|
414
|
+
// inject the resolved bridge port (numeric literal) BEFORE the page runs, so
|
|
415
|
+
// the shell/engine talk to the daemon this driver owns. addInitScript runs
|
|
416
|
+
// ahead of every page script, and the vite dev plugin only fills the value in
|
|
417
|
+
// when it is still unset, so this one wins. plain assignment, NOT
|
|
418
|
+
// defineProperty: other injectors also assign to it, and a non-writable
|
|
419
|
+
// property would throw at that assignment and crash boot.
|
|
420
|
+
const bridgePortInject = bridgePort
|
|
421
|
+
? 'window.__sootsimBridgePort = ' + Number(bridgePort) + ';'
|
|
422
|
+
: '';
|
|
423
|
+
await context.addInitScript({
|
|
424
|
+
content: 'Object.defineProperty(window, "__sootsimHostMeta", { value: ' + JSON.stringify(hostMeta) + ', configurable: true });' + bridgePortInject,
|
|
425
|
+
});
|
|
426
|
+
await context.exposeBinding('__sootsimHostClose', async () => {
|
|
427
|
+
await shutdown(0);
|
|
428
|
+
});
|
|
429
|
+
const connectTimeoutMs = Number(process.env.SOOTSIM_PW_CONNECT_TIMEOUT_MS || 120000);
|
|
430
|
+
if (connectAckFile) {
|
|
431
|
+
connectAckPoll = setInterval(() => {
|
|
432
|
+
if (ackFileExists()) markConnected();
|
|
433
|
+
}, 500);
|
|
434
|
+
if (typeof connectAckPoll.unref === 'function') connectAckPoll.unref();
|
|
435
|
+
}
|
|
436
|
+
connectTimer = setTimeout(() => {
|
|
437
|
+
if (ackFileExists()) {
|
|
438
|
+
markConnected();
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (connected) return;
|
|
442
|
+
process.stderr.write('[connect-timeout] sim did not register with the bridge within ' + connectTimeoutMs + 'ms; closing playwright host\\n');
|
|
443
|
+
void shutdown(2);
|
|
444
|
+
}, Number.isFinite(connectTimeoutMs) && connectTimeoutMs > 0 ? connectTimeoutMs : 120000);
|
|
445
|
+
if (typeof connectTimer.unref === 'function') connectTimer.unref();
|
|
446
|
+
const page = await context.newPage();
|
|
447
|
+
if (hardwareGpuRequired) {
|
|
448
|
+
assertNoUnsafeSwiftShaderFlag();
|
|
449
|
+
const gpu = await page.evaluate(() => {
|
|
450
|
+
const canvas = document.createElement('canvas');
|
|
451
|
+
const gl =
|
|
452
|
+
canvas.getContext('webgl2', { powerPreference: 'high-performance' }) ||
|
|
453
|
+
canvas.getContext('webgl', { powerPreference: 'high-performance' });
|
|
454
|
+
if (!gl) return { renderer: null, vendor: null };
|
|
455
|
+
const info = gl.getExtension('WEBGL_debug_renderer_info');
|
|
456
|
+
return {
|
|
457
|
+
renderer: info ? String(gl.getParameter(info.UNMASKED_RENDERER_WEBGL)) : null,
|
|
458
|
+
vendor: info ? String(gl.getParameter(info.UNMASKED_VENDOR_WEBGL)) : null,
|
|
459
|
+
};
|
|
460
|
+
});
|
|
461
|
+
if (!gpu.renderer) {
|
|
462
|
+
throw new Error(
|
|
463
|
+
'[playwright-driver] could not prove a hardware WebGL renderer; refusing local render-heavy launch'
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
if (softwareRendererPattern.test(gpu.renderer)) {
|
|
467
|
+
throw new Error('[playwright-driver] refused software WebGL renderer: ' + gpu.renderer);
|
|
468
|
+
}
|
|
469
|
+
assertNoUnsafeSwiftShaderFlag();
|
|
470
|
+
process.stderr.write(
|
|
471
|
+
'[playwright-driver] hardware WebGL renderer: ' + gpu.renderer +
|
|
472
|
+
(gpu.vendor ? ' (' + gpu.vendor + ')' : '') + '\\n'
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
// surface page-side failures (engine boot crash, failed WS registration)
|
|
476
|
+
// to stderr so a sim that never connects produces a real diagnostic
|
|
477
|
+
// instead of a silent "timed out waiting for opened sim to connect".
|
|
478
|
+
page.on('pageerror', (e) => {
|
|
479
|
+
process.stderr.write('[pageerror] ' + ((e && e.stack) || e) + '\\n');
|
|
480
|
+
});
|
|
481
|
+
page.on('console', (m) => {
|
|
482
|
+
if (m.type() === 'error') {
|
|
483
|
+
process.stderr.write('[console.error] ' + m.text() + '\\n');
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
page.on('crash', () => process.stderr.write('[page] renderer crashed\\n'));
|
|
487
|
+
try {
|
|
488
|
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 60000 });
|
|
489
|
+
} catch (err) {
|
|
490
|
+
process.stderr.write('[goto] ' + String((err && err.message) || err) + '\\n');
|
|
491
|
+
}
|
|
492
|
+
keepAlive = setInterval(() => {}, 1 << 30);
|
|
493
|
+
// browser disconnect (e.g. user killed chrome from outside) \u2192 tear down.
|
|
494
|
+
// we are persistent-only now, so .browser() is the only handle to it.
|
|
495
|
+
try {
|
|
496
|
+
const b = context.browser && context.browser();
|
|
497
|
+
if (b && typeof b.on === 'function') b.on('disconnected', () => { void shutdown(0); });
|
|
498
|
+
} catch {}
|
|
499
|
+
context.on('close', () => { void shutdown(0); });
|
|
500
|
+
page.on('close', () => { void shutdown(0); });
|
|
501
|
+
})().catch((err) => {
|
|
502
|
+
process.stderr.write(String((err && err.stack) || err) + '\\n');
|
|
503
|
+
process.exit(1);
|
|
504
|
+
});
|
|
505
|
+
`;function ue(){let e=I();return e?{available:!0,reason:null,detail:`resolved via ${e.spec}@${e.version}`}:{available:!1,reason:"playwright not installed in the current workspace"}}function he(e,t){return process.platform!=="linux"||e.headless||process.env.DISPLAY||process.env.WAYLAND_DISPLAY||!/missing x server|cannot open display|x server|x11/i.test(t)?null:" hint: linux without DISPLAY/WAYLAND_DISPLAY \u2014 rerun without --headed (or add --headless) to run playwright headless."}function pe(e){return e.profileId?x(L(e.profileId).id):e.ephemeralProfile?ae(B(G(),"sootsim-playwright-profile-")):""}async function fe(e){let t=I();if(!t)return{launched:!1,message:"playwright not installed \u2014 run `bun add -D playwright` first"};if(!e.url)return{launched:!1,message:"playwright driver requires a target url"};let r=e.ownerPid;if(r===void 0||!Number.isInteger(r)||r<=1)return{launched:!1,message:"playwright driver requires a valid owning session process"};let o={...process.env},n=U(t,o);if(!n.ok)return{launched:!1,message:`playwright browser provisioning failed: ${n.message}`};let i=B(G(),`sootsim-playwright-host-${Date.now().toString(36)}-${process.pid}.log`),a=`${i}.connected`,l=le(i,"a");try{let s=ie(process.execPath,["-e",de],{detached:!0,stdio:["ignore","ignore",l],env:{...o,SOOTSIM_PW_MODULE:t.modulePath,SOOTSIM_PW_URL:e.url,SOOTSIM_PW_BRIDGE_PORT:e.bridgePort?String(e.bridgePort):"",SOOTSIM_PW_HEADLESS:e.headless??!0?"1":"0",SOOTSIM_PW_USERDATADIR:pe(e),SOOTSIM_PW_CDP_PORT:e.cdpPort?String(e.cdpPort):"",...e.viewport?{SOOTSIM_PW_VIEWPORT:`${e.viewport.width}x${e.viewport.height}`}:{},SOOTSIM_PW_CONNECTED_ACK_FILE:a,SOOTSIM_PW_CONNECT_TIMEOUT_MS:String(e.connectTimeoutMs??12e4),SOOTSIM_PW_OWNER_PID:String(r)}});s.unref();let p=await new Promise(c=>{let w=setTimeout(()=>c(null),4e3);s.once("exit",q=>{clearTimeout(w),c(q??0)})});if(p!==null){let c=ce(i,"utf8").trim(),w=he(e,c);return{launched:!1,message:`playwright host exited early (code ${p}) \u2014 host log ${i}${c?`:
|
|
506
|
+
${c}`:""}${w?`
|
|
507
|
+
${w}`:""}`}}let f=C(r),g=` \u2014 browser closes when pid ${r}${f?` (${f})`:""} exits`;return{launched:!0,message:`playwright chrome launched \u2192 ${e.url}${g}`,pid:s.pid,target:t.spec,attachUrl:e.url,connectAckFile:a,diagnosticLogPath:i}}catch(s){return{launched:!1,message:`playwright launch failed: ${s instanceof Error?s.message:String(s)}`}}finally{se(l)}}var j={id:"playwright",name:"playwright",description:"programmatic chromium via the playwright package \u2014 headless default",kind:"automation",availability:ue,launch:fe};var m=[W,j];function $e(){return m}function Fe(e){return m.find(t=>t.id===e)??null}function Ue(e,t){if(e)return m.find(o=>o.id===e)??null;for(let r of t){let o=m.find(n=>n.id===r);if(o&&o.availability().available)return o}return null}function Ge(){return m.map(e=>{let t=e.availability();return{id:e.id,name:e.name,kind:e.kind,description:e.description,available:t.available,reason:t.reason,detail:t.detail??null}})}export{K as a,L as b,V as c,ve as d,X as e,W as f,j as g,m as h,$e as i,Fe as j,Ue as k,Ge as l};
|