修复root用户登录的浏览器无法跳转vscode问题

永久修复------让 Chrome 自动调用带 --no-sandbox 的 VS Code

如果您坚持 要让 Chrome 点击 vscode:// 链接时自动拉起 VS Code,必须绕过 Chrome 自身的协议处理限制。以下是仅有的两种可靠方法

方法 A:创建自定义协议处理脚本(推荐)

原理 :将 vscode:// 协议委托给一个 Shell 脚本,脚本调用 VS Code 并附加 --no-sandbox

  1. 创建脚本 /usr/local/bin/vscode-handler.sh

    bash

    bash 复制代码
    #!/bin/bash
    /usr/share/code/code --no-sandbox --open-url "$1"

    bash

    bash 复制代码
    chmod +x /usr/local/bin/vscode-handler.sh
  2. 创建自定义 .desktop 文件

    bash

    bash 复制代码
    nano /usr/share/applications/vscode-nosandbox.desktop

    内容:

    text

    ini 复制代码
    [Desktop Entry]
    Name=Visual Studio Code (No Sandbox)
    Comment=Code Editing. Redefined.
    Exec=/usr/local/bin/vscode-handler.sh %u
    Icon=code
    Terminal=false
    Type=Application
    MimeType=x-scheme-handler/vscode;
    Categories=Development;
  3. 注册协议处理器

    bash

    bash 复制代码
    update-desktop-database /usr/share/applications/
    xdg-mime default vscode-nosandbox.desktop x-scheme-handler/vscode
  4. 验证

    bash

    bash 复制代码
    xdg-mime query default x-scheme-handler/vscode
    # 应输出 vscode-nosandbox.desktop

现在 Chrome 点击任何 vscode:// 链接,都会通过脚本启动带 --no-sandbox 的 VS Code。

相关推荐
烧饼Fighting15 小时前
Ubuntu24.04换源和解决物理机无法复制粘贴到虚拟机问题
ubuntu
The️17 小时前
Linux驱动开发之Makefile
linux·驱动开发·mcu·ubuntu
yunianshu18 小时前
Ubuntu 24.04 双系统安装(不使用 U 盘,亲测有效)
linux·运维·ubuntu
ZaneAI19 小时前
🚀 古董笔记本变废为宝:安装 OpenClaw + MiniMax,打造 24 小时在线 AI 助理
ubuntu·agent
xin_yao_xin2 天前
查询端口占用小脚本(ubuntu)
linux·运维·ubuntu
wangjialelele2 天前
Linux信号处理、中断、与页表映射
linux·运维·ubuntu·centos·信号处理·gnu
非自律懒癌患者2 天前
Ubuntu 浏览器建立安全连接失败
linux·运维·ubuntu
HIT_Weston2 天前
129、【Ubuntu】【Hugo】首页板块配置(一)
linux·运维·ubuntu
YYYing.2 天前
【Linux/C++文件篇(一) 】标准I/O与文件I/O基础 :一文掌握文件操作的核心
linux·运维·c语言·c++·ubuntu·centos