You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Gulp+Browsersync启动带调试端口参数的Chrome浏览器

Fix: Launch Chrome with Remote Debugging Port via Gulp + Browsersync

Got it, let's get this sorted for you! The problem with your earlier attempts is that passing the port parameter as part of a single string makes Browsersync treat the whole thing as the browser executable name—so it can't find the correct Chrome binary. Instead, you need to use an array to separate the browser identifier and its command-line arguments.

Working Code Snippet

Replace your existing browserSync task with this:

gulp.task("browserSync", function () {
  browserSync.init({
    server: { baseDir: "src" },
    browser: ["google chrome", "--remote-debugging-port=9222"],
  });
});

Why This Works

Browsersync’s browser option supports array values where:

  • The first element is the browser’s recognized name (Browsersync handles cross-OS lookup for common browsers like "google chrome")
  • Every element after that is a separate command-line flag you want to pass to the browser

Fallback for Windows Users (If Needed)

If the above doesn’t work (unlikely, but possible if Chrome isn’t in your system PATH), you can specify the full path to chrome.exe:

browser: ["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", "--remote-debugging-port=9222"],

After updating your Gulpfile, run the browserSync task. Chrome will launch with the remote debugging port enabled, and you’ll be able to connect it to the VS Code Chrome Devtools Extension smoothly.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:52:29