You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

咨询:Chrome中能否伪造自定义参数的USB设备,还是需创建虚拟USB设备?

解决方案:两种路径实现自定义USB设备标识

Great question! You've got two solid paths to achieve your goal—one that works entirely within Chrome (no system-level tweaks needed), and another that creates a full system-level virtual USB device. Let's break them down:

一、仅通过Chrome浏览器实现(快速测试首选)

If you only need to fool the Chrome-based website's WebUSB checks, you don't need to mess with system-level virtual hardware. Here are two easy methods:

1. Chrome DevTools内置的WebUSB模拟(Chrome 94+)

Chrome's DevTools has a built-in tool to mock USB devices directly, which lets you set custom manufacturer_name and product_name values in seconds:

  • Open DevTools (F12), click the three-dot menu in the top-right → More toolsWebUSB
  • Click the Add device button, then fill in your desired manufacturer and product names in the form (you can leave other fields like vendor ID/product ID as defaults if you don't need them)
  • Save the mock device, and the next time the site calls the WebUSB API, it'll detect your fake device and send the payload with your custom values.

2. Chrome扩展拦截并修改WebUSB responses

For more dynamic control (like changing values on the fly or automating tests), you can build a tiny Chrome extension to override the WebUSB API calls and return your custom device data. Here's a quick snippet for the extension's content script:

// Override the getDevices method to return our fake USB device
const originalGetDevices = navigator.usb.getDevices;
navigator.usb.getDevices = async () => {
  const fakeDevice = {
    manufacturerName: "Your Custom Manufacturer",
    productName: "Your Custom Product",
    vendorId: 0x1234, // Random valid vendor ID
    productId: 0x5678 // Random valid product ID
    // Add other required properties if the site checks for them
  };
  return [fakeDevice];
};

This will make the site think your custom device is connected, without any actual hardware.

二、系统级虚拟USB设备(接近真实硬件场景)

If the site relies on low-level USB driver interactions (not just the WebUSB API), you'll need to create a system-level virtual USB device. This is more involved but mimics a real hardware device:

  • Windows: Use tools like USBIP or third-party virtual USB drivers to define a custom device descriptor with your desired manufacturer and product names.
  • macOS/Linux: Leverage libraries like libusb alongside system-specific frameworks (Linux's gadget subsystem, macOS's IOUSBFamily tools) to craft a virtual USB device with custom string descriptors.

Final Verdict

For your use case (a Chrome-only site using WebUSB), start with the DevTools WebUSB mock or Chrome extension—they're fast, no-fuss, and perfect for testing your challenge task. Only go the system-level virtual device route if you need full hardware emulation.

内容的提问来源于stack exchange,提问作者krise

火山引擎 最新活动