技能 编程开发 Web容器诊断工具

Web容器诊断工具

v20260423
stackblitz-debug-bundle
本工具包用于收集Web容器(WebContainer)环境的全面诊断信息。它可以检查容器的启动状态、文件系统完整性、进程列表以及现代浏览器支持情况。适用于使用StackBlitz SDK或WebContainers进行开发和调试,帮助开发者解决复杂的环境兼容性问题。
获取技能
424 次下载
概览

StackBlitz Debug Bundle

Overview

Collect WebContainer diagnostic info: boot state, file system, process list.

Instructions

Step 1: Check Boot State

async function diagnoseWebContainer(wc: WebContainer) {
  const report: Record<string, any> = {};

  // File system check
  try {
    const entries = await wc.fs.readdir('/');
    report.filesystem = { status: 'ok', rootEntries: entries.length };
  } catch (e: any) {
    report.filesystem = { status: 'error', message: e.message };
  }

  // Node.js check
  try {
    const proc = await wc.spawn('node', ['-e', 'console.log(JSON.stringify({version: process.version, arch: process.arch}))']);
    let output = '';
    proc.output.pipeTo(new WritableStream({ write(data) { output += data; } }));
    await proc.exit;
    report.node = JSON.parse(output);
  } catch (e: any) {
    report.node = { status: 'error', message: e.message };
  }

  // Memory check
  try {
    const proc = await wc.spawn('node', ['-e', 'console.log(JSON.stringify(process.memoryUsage()))']);
    let output = '';
    proc.output.pipeTo(new WritableStream({ write(data) { output += data; } }));
    await proc.exit;
    report.memory = JSON.parse(output);
  } catch { report.memory = 'unavailable'; }

  return report;
}

Step 2: Check Browser Support

function checkBrowserSupport() {
  return {
    sharedArrayBuffer: typeof SharedArrayBuffer !== 'undefined',
    crossOriginIsolated: window.crossOriginIsolated,
    serviceWorker: 'serviceWorker' in navigator,
    userAgent: navigator.userAgent,
  };
}

Error Handling

Check Expected Failed Action
SharedArrayBuffer defined Add COOP/COEP headers
crossOriginIsolated true Check all headers present
Node.js version v18+ WebContainer ships its own
Root FS entries > 0 Re-mount files

Resources

Next Steps

For resource limits, see stackblitz-rate-limits.

信息
Category 编程开发
Name stackblitz-debug-bundle
版本 v20260423
大小 2.46KB
更新时间 2026-04-28
语言