Using VSCode Web Server Variant

Last tested version is 1.67.2, may become invalid in a future version.

Why & Why Not?

Advantages

Disadvantages

Guide

First, the download link is server-win32-x64-web and server-linux-x64-web.

https://update.code.visualstudio.com/latest/ {target} /stable

Create directory named vscode with folder data, inner and misc.

Extract the package to inner, the you can directly execute ./inner/server.sh(bat).

To change data directory, use custom token and port, ./run.sh:

export VSCODE_AGENT_FOLDER=./data
./inner/bin/code-server.sh --port=8109 --connection-token=mytoken

But a lot of inconvenience here, such as build tasks always fail when offline. So there is a patch ./misc/patch.js:

"use strict"; // Last Tested Version: 1.67.2
const patch = (path, replaceList) => {
  const fs = require("fs");
  const filePath = require("path").join(__dirname, "../inner", path);
  const bakPath = filePath + `.bak`;
  if (!fs.existsSync(bakPath)) fs.renameSync(filePath, bakPath);
  let content = fs.readFileSync(bakPath).toString();
  for (const [search, value] of replaceList) {
    const fn = search instanceof RegExp ? "replace" : "replaceAll";
    content = content[fn](search, value);
  }
  fs.writeFileSync(filePath, content);
  console.log("patched: " + path);
};
patch("./out/vs/workbench/workbench.web.main.js", [
  // Webview: replaced with local server to allow offline work
  [
    `"https://{{uuid}}.vscode-cdn.net/{{quality}}/{{commit}}`,
    `location.origin+"/static`,
  ],
]);
patch("./out/vs/workbench/contrib/webview/browser/pre/main.js", [
  // Webview: bypass hostname vertify
  [/BigInt.+?catch/, "location.hostname}catch"],
]);
patch("./out/vs/workbench/contrib/webview/browser/pre/service-worker.js", [
  // Webview: bypass requests
  [`addEventListener("fetch",`, "NaN;("],
]);
patch("./out/vs/workbench/api/node/extensionHostProcess.js", [
  // Webview: block resources to avoid long waiting
  [`webviewResourceBaseHost="`, `webviewResourceBaseHost="//`],
]);