@iwsdk/vite-plugin-dev 0.3.2 → 0.4.1

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/dist/index.js CHANGED
@@ -1000,24 +1000,102 @@ async function doChromiumInstall() {
1000
1000
  });
1001
1001
  });
1002
1002
  }
1003
+ /**
1004
+ * Check whether a GPU device is available. On macOS/Windows this always
1005
+ * returns true (Metal/D3D11 require a GPU by definition). On Linux it
1006
+ * probes /dev/dri/ for render nodes, which works in Docker, VMs, and
1007
+ * bare-metal environments without requiring external tools.
1008
+ */
1009
+ function hasGpuDevice() {
1010
+ if (os.platform() !== 'linux') {
1011
+ return true;
1012
+ }
1013
+ try {
1014
+ const entries = fs.readdirSync('/dev/dri');
1015
+ return entries.some((e) => e.startsWith('renderD') || e.startsWith('card'));
1016
+ }
1017
+ catch {
1018
+ return false;
1019
+ }
1020
+ }
1021
+ const VALID_GPU_VALUES = ['auto', 'gpu', 'swiftshader'];
1022
+ /**
1023
+ * Resolve the GPU / ANGLE backend for Chromium.
1024
+ *
1025
+ * Override with IWSDK_GPU env var:
1026
+ * - "auto" (default) auto-detect; hardware GL when a GPU is present,
1027
+ * SwiftShader otherwise
1028
+ * - "gpu" force hardware GL (fails if no GPU)
1029
+ * - "swiftshader" force CPU-based SwiftShader rendering
1030
+ */
1031
+ function resolveGpuBackend() {
1032
+ const envOverride = process.env.IWSDK_GPU?.toLowerCase();
1033
+ if (envOverride !== undefined && !VALID_GPU_VALUES.includes(envOverride)) {
1034
+ console.warn(`⚠️ IWSDK: Unknown IWSDK_GPU value "${process.env.IWSDK_GPU}". ` +
1035
+ 'Valid values: auto, gpu, swiftshader. Falling back to auto-detect.');
1036
+ }
1037
+ if (envOverride === 'swiftshader') {
1038
+ return {
1039
+ kind: 'swiftshader',
1040
+ useGl: 'angle',
1041
+ useAngle: 'swiftshader',
1042
+ reason: 'env-override',
1043
+ };
1044
+ }
1045
+ const platform = os.platform();
1046
+ if (platform === 'darwin') {
1047
+ return {
1048
+ kind: 'hardware',
1049
+ useGl: 'angle',
1050
+ useAngle: 'metal',
1051
+ reason: 'auto',
1052
+ };
1053
+ }
1054
+ if (platform === 'win32') {
1055
+ return {
1056
+ kind: 'hardware',
1057
+ useGl: 'angle',
1058
+ useAngle: 'd3d11',
1059
+ reason: 'auto',
1060
+ };
1061
+ }
1062
+ // Linux: honour explicit "gpu" override, otherwise auto-detect
1063
+ if (envOverride === 'gpu') {
1064
+ return {
1065
+ kind: 'hardware',
1066
+ useGl: 'angle',
1067
+ useAngle: 'gl',
1068
+ reason: 'env-override',
1069
+ };
1070
+ }
1071
+ if (hasGpuDevice()) {
1072
+ return { kind: 'hardware', useGl: 'angle', useAngle: 'gl', reason: 'auto' };
1073
+ }
1074
+ return {
1075
+ kind: 'swiftshader',
1076
+ useGl: 'angle',
1077
+ useAngle: 'swiftshader',
1078
+ reason: 'auto',
1079
+ };
1080
+ }
1003
1081
  async function launchManagedBrowser(url, headless, verbose, viewport = null, screenshotSize = {
1004
1082
  width: 800,
1005
1083
  height: 800,
1006
1084
  }, traceMcp = false) {
1007
1085
  await ensureChromiumInstalled();
1008
- // Select GPU backend based on platform
1009
- const angleBackend = os.platform() === 'darwin'
1010
- ? 'metal'
1011
- : os.platform() === 'win32'
1012
- ? 'd3d11'
1013
- : 'gl';
1086
+ const backend = resolveGpuBackend();
1087
+ console.log(backend.kind === 'swiftshader'
1088
+ ? backend.reason === 'env-override'
1089
+ ? '🖥️ IWSDK: Using SwiftShader (software rendering) — IWSDK_GPU=swiftshader'
1090
+ : '🖥️ IWSDK: Using SwiftShader (software rendering) — no GPU detected'
1091
+ : `🖥️ IWSDK: Using hardware GPU (${backend.useAngle})`);
1014
1092
  const browser = await chromium.launch({
1015
1093
  headless,
1016
1094
  args: [
1017
- '--enable-webgl', // Ensure WebGL is available
1018
- '--use-gl=angle', // Use ANGLE for WebGL
1019
- `--use-angle=${angleBackend}`, // Platform-specific GPU backend
1020
- '--disable-background-timer-throttling', // No rAF throttling
1095
+ '--enable-webgl',
1096
+ `--use-gl=${backend.useGl}`,
1097
+ `--use-angle=${backend.useAngle}`,
1098
+ '--disable-background-timer-throttling',
1021
1099
  '--disable-renderer-backgrounding',
1022
1100
  ],
1023
1101
  });
@@ -1070,7 +1148,7 @@ async function launchManagedBrowser(url, headless, verbose, viewport = null, scr
1070
1148
  window.__IWER_MCP_MANAGED = true;
1071
1149
  window.__IWSDK_MCP_TRACE = traceEnabled;
1072
1150
  }, traceMcp);
1073
- await page.goto(url, { waitUntil: 'networkidle' });
1151
+ await page.goto(url, { waitUntil: 'commit' });
1074
1152
  // Wait for IWER to inject and XR device to be available
1075
1153
  await page.waitForFunction(() => window.IWER_DEVICE !== undefined, {
1076
1154
  timeout: 15000,
@@ -1595,16 +1673,15 @@ function iwsdkDev(options = {}) {
1595
1673
  commandReady,
1596
1674
  connectedClientCount,
1597
1675
  lastTransitionAt: new Date().toISOString(),
1598
- ...(options.lastBridgeConnectedAt ?? previous?.lastBridgeConnectedAt
1676
+ ...((options.lastBridgeConnectedAt ?? previous?.lastBridgeConnectedAt)
1599
1677
  ? {
1600
1678
  lastBridgeConnectedAt: options.lastBridgeConnectedAt ??
1601
1679
  previous?.lastBridgeConnectedAt,
1602
1680
  }
1603
1681
  : {}),
1604
- ...(options.lastCommandReadyAt ?? previous?.lastCommandReadyAt
1682
+ ...((options.lastCommandReadyAt ?? previous?.lastCommandReadyAt)
1605
1683
  ? {
1606
- lastCommandReadyAt: options.lastCommandReadyAt ??
1607
- previous?.lastCommandReadyAt,
1684
+ lastCommandReadyAt: options.lastCommandReadyAt ?? previous?.lastCommandReadyAt,
1608
1685
  }
1609
1686
  : {}),
1610
1687
  ...(options.lastError ? { lastError: options.lastError } : {}),
@@ -1937,7 +2014,8 @@ function iwsdkDev(options = {}) {
1937
2014
  }
1938
2015
  return;
1939
2016
  }
1940
- if (parsed.method === 'get_console_logs' && typeof parsed.id === 'string') {
2017
+ if (parsed.method === 'get_console_logs' &&
2018
+ typeof parsed.id === 'string') {
1941
2019
  intercepted = true;
1942
2020
  try {
1943
2021
  const readiness = await ensureBrowserCommandReady('get_console_logs');
@@ -1980,7 +2058,8 @@ function iwsdkDev(options = {}) {
1980
2058
  }
1981
2059
  return;
1982
2060
  }
1983
- if (parsed.method === 'screenshot' && typeof parsed.id === 'string') {
2061
+ if (parsed.method === 'screenshot' &&
2062
+ typeof parsed.id === 'string') {
1984
2063
  intercepted = true;
1985
2064
  try {
1986
2065
  const readiness = await ensureBrowserCommandReady('screenshot');