Skip to content

Instantly share code, notes, and snippets.

@if1live
Created January 8, 2024 12:59
Show Gist options
  • Save if1live/8d1b310ae615cbc803dee4064b3fadfd to your computer and use it in GitHub Desktop.
Save if1live/8d1b310ae615cbc803dee4064b3fadfd to your computer and use it in GitHub Desktop.
override globalThis.fetch
// https://corsproxy.io/
const fetch_base = globalThis.fetch;
const fetch_next: typeof fetch_base = async (url, init) => {
if (typeof url === "string") {
const urlObj = new URL(url);
if (urlObj.hostname === "www.youtube.com") {
const proxyUrl = `https://corsproxy.io/?${encodeURIComponent(url)}`;
return await fetch_base(proxyUrl, init);
}
}
// else
return await fetch_base(url, init);
};
globalThis.fetch = fetch_next as typeof fetch_base;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment