Skip to content

Instantly share code, notes, and snippets.

@vrocky
Last active May 7, 2025 11:18
Show Gist options
  • Save vrocky/b4b55592235dc53022a2bbc887ff3eb1 to your computer and use it in GitHub Desktop.
Save vrocky/b4b55592235dc53022a2bbc887ff3eb1 to your computer and use it in GitHub Desktop.
đź”§ Script to automatically fetch and download the latest VSIX package of a Visual Studio Code extension from its Marketplace page. It parses the page to extract the publisher, extension name, and latest version, then builds the VSIX URL and downloads the file automatically.

Gist Description

đź”§ Script to automatically fetch and download the latest VSIX package of a Visual Studio Code extension from its Marketplace page. It parses the page to extract the publisher, extension name, and latest version, then builds the VSIX URL and downloads the file automatically.


README.md

VSCode Marketplace Latest VSIX Downloader

This script automatically fetches and downloads the latest VSIX package of a Visual Studio Code extension from its Marketplace page.

✨ Features

  • âś… Extracts publisher and extension name from og:url
  • âś… Reads the latest version from the embedded Marketplace JSON
  • âś… Builds the correct VSIX download URL
  • âś… Automatically downloads the .vsix file in the browser

📦 How to use

  1. Go to the extension’s Marketplace page

    Example:

    https://marketplace.visualstudio.com/items?itemName=GitHub.copilot
    
  2. Open browser devtools → Console tab

  3. Paste the script and hit Enter

The script will automatically:

  • Fetch the latest .vsix package
  • Trigger a download in your browser

âš™ Script

(async () => {
  const og = document.querySelector('meta[property="og:url"]');
  if (!og) throw new Error('og:url meta tag not found');
  const itemName = new URL(og.content).searchParams.get('itemName');
  if (!itemName) throw new Error('itemName not in og:url');
  const [publisher, extension] = itemName.split('.');
  const ji = document.querySelector('script.jiContent[type="application/json"]');
  if (!ji) throw new Error('Marketplace JSON blob not found');
  const meta = JSON.parse(ji.textContent);
  const version = meta.Versions?.[0]?.version;
  if (!version) throw new Error('No version info found in JSON');
  const vsixUrl = `https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher}/vsextensions/${extension}/${version}/vspackage`;
  const resp = await fetch(vsixUrl);
  if (!resp.ok) throw new Error(`VSIX fetch failed: ${resp.status}`);
  const blob = await resp.blob();
  const a = document.createElement('a');
  a.href = URL.createObjectURL(blob);
  a.download = `${publisher}.${extension}-${version}.vsix`;
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
})();

âš  Notes

  • Works only on the extension’s Marketplace page, not directly from raw URLs.
  • You need to manually paste it in the browser console; it is not a userscript.
  • Useful when the direct download link is broken or unavailable.

📜 License

MIT License

(async () => {
// 1. Extract “Publisher.Extension” from the page’s <meta og:url>
const og = document.querySelector('meta[property="og:url"]');
if (!og) throw new Error('og:url meta tag not found');
const itemName = new URL(og.content).searchParams.get('itemName');
if (!itemName) throw new Error('itemName not in og:url');
const [publisher, extension] = itemName.split('.');
// 2. Grab the embedded Marketplace JSON (contains Versions[]) :contentReference[oaicite:0]{index=0}
const ji = document.querySelector('script.jiContent[type="application/json"]');
if (!ji) throw new Error('Marketplace JSON blob not found');
const meta = JSON.parse(ji.textContent);
// 3. Read the first (latest) version from that JSON :contentReference[oaicite:1]{index=1}
const version = meta.Versions?.[0]?.version;
if (!version) throw new Error('No version info found in JSON');
// 4. Build the VSIX URL
const vsixUrl = `https://marketplace.visualstudio.com/_apis/public/gallery/` +
`publishers/${publisher}/vsextensions/${extension}/${version}/vspackage`;
// 5. Fetch the .vsix and auto‑download it
const resp = await fetch(vsixUrl);
if (!resp.ok) throw new Error(`VSIX fetch failed: ${resp.status}`);
const blob = await resp.blob();
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `${publisher}.${extension}-${version}.vsix`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
})();
(() => {
try {
// 1. Read the extension’s “itemName” from the og:url meta‑tag
const og = document.querySelector('meta[property="og:url"]');
if (!og) throw new Error('meta[property="og:url"] not found');
const itemName = new URL(og.content).searchParams.get('itemName');
if (!itemName) throw new Error('itemName query‑param missing');
const [publisher, extension] = itemName.split('.');
// 2. Grab the embedded Marketplace JSON blob
const ji = document.querySelector('script.jiContent[type="application/json"]');
if (!ji) throw new Error('embedded marketplace JSON not found');
const meta = JSON.parse(ji.textContent);
// 3. Extract the latest version
const version = meta.Versions?.[0]?.version;
if (!version) throw new Error('no version info in JSON');
// 4. Build the VSIX URL
const vsixUrl =
`https://marketplace.visualstudio.com/_apis/public/gallery/` +
`publishers/${publisher}/vsextensions/${extension}/${version}/vspackage`;
// 5. Print it
console.log('VSIX URL →', vsixUrl);
} catch (e) {
console.error(e.message);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment