From bfc784e0a19c0910e1f6dff319d0154a58241c43 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 20 Sep 2026 05:27:53 +0000 Subject: [PATCH 1/5] docs: add Cloudflare Workers deployment and usage section to README Co-authored-by: bxnxnxhzhdhdjdjjx-spec <315051886+bxnxnxhzhdhdjdjjx-spec@users.noreply.github.com> --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/README.md b/README.md index 01aa833a0..d6fa5ce0d 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,76 @@ const innertube = await Innertube.create(/* options */); For detailed usage, read the [YouTube.js Guide and API Documentation](https://ytjs.dev). +## Cloudflare Workers Usage & Deployment + +To deploy and use YouTube.js on Cloudflare Workers, follow these steps: + +### 1. Prerequisites +- Node.js installed on your system. +- A Cloudflare account. +- `wrangler` CLI installed (`npm install -g wrangler` or via `npx wrangler`). + +### 2. Project Setup +Create a new project directory and initialize Wrangler: + +```bash +mkdir my-cf-worker +cd my-cf-worker +npm init -y +npm install youtubei.js@latest +npm install -D wrangler typescript @cloudflare/workers-types +``` + +### 3. Configure `wrangler.toml` +Create a `wrangler.toml` file in your project root directory: + +```toml +name = "my-youtubei-worker" +main = "src/index.ts" +compatibility_date = "2024-02-08" +``` + +### 4. Write Worker Code (`src/index.ts`) +Import `Innertube` specifically from `youtubei.js/cf-worker`: + +```ts +import { Innertube } from 'youtubei.js/cf-worker'; + +export interface Env {} + +export default { + async fetch( + request: Request, + env: Env, + ctx: ExecutionContext + ): Promise { + // Note: Initialize Innertube inside the fetch handler, not in the global scope + const yt = await Innertube.create(); + + const video = await yt.getInfo('jNQXAC9IVRw'); + + return new Response(JSON.stringify({ + title: video.basic_info.title, + description: video.basic_info.short_description, + }), { + headers: { 'Content-Type': 'application/json' } + }); + }, +}; +``` + +### 5. Local Development & Deployment + +**Local testing:** +```bash +npx wrangler dev +``` + +**Deploy to Cloudflare Workers:** +```bash +npx wrangler deploy +``` + ## Contributing All contributions are welcome, big or small. If you want to contribute, take a look at the [issues page](https://github.com/LuanRT/YouTube.js/issues) and our [guidelines](https://github.com/LuanRT/YouTube.js/blob/main/CONTRIBUTING.md). From d4a5a0a0ded58b88ee250a96e112e4049228de72 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 20 Sep 2026 05:52:51 +0000 Subject: [PATCH 2/5] fix(cf-worker): add nodejs_compat flag to Wrangler configuration Cloudflare Workers requires the `nodejs_compat` compatibility flag and a recent `compatibility_date` (2024-09-23 or later) when bundling modules that rely on Node.js built-ins like `module` or `node:` specifiers. Update Wrangler configuration in example and README documentation accordingly. Co-authored-by: bxnxnxhzhdhdjdjjx-spec <315051886+bxnxnxhzhdhdjdjjx-spec@users.noreply.github.com> --- README.md | 3 ++- examples/cloudflare-worker/wrangler.toml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d6fa5ce0d..e11521df1 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,8 @@ Create a `wrangler.toml` file in your project root directory: ```toml name = "my-youtubei-worker" main = "src/index.ts" -compatibility_date = "2024-02-08" +compatibility_date = "2024-09-23" +compatibility_flags = ["nodejs_compat"] ``` ### 4. Write Worker Code (`src/index.ts`) diff --git a/examples/cloudflare-worker/wrangler.toml b/examples/cloudflare-worker/wrangler.toml index e937d8c48..4c34423d2 100644 --- a/examples/cloudflare-worker/wrangler.toml +++ b/examples/cloudflare-worker/wrangler.toml @@ -1,3 +1,4 @@ name = "cf-worker-youtubei" main = "src/index.ts" -compatibility_date = "2024-02-08" \ No newline at end of file +compatibility_date = "2024-09-23" +compatibility_flags = ["nodejs_compat"] From 3cd8d4700ec8d508d240d7ad11705f6899480fc1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 20 Sep 2026 05:58:22 +0000 Subject: [PATCH 3/5] fix(cf-worker): add wrangler.toml and nodejs_compat flag Add wrangler.toml at repository root targeting bundle/cf-worker.js with nodejs_compat flag and compatibility_date 2024-09-23 so Cloudflare Workers deployments succeed. Also update example wrangler.toml and README documentation. Co-authored-by: bxnxnxhzhdhdjdjjx-spec <315051886+bxnxnxhzhdhdjdjjx-spec@users.noreply.github.com> --- wrangler.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 wrangler.toml diff --git a/wrangler.toml b/wrangler.toml new file mode 100644 index 000000000..06fa36c45 --- /dev/null +++ b/wrangler.toml @@ -0,0 +1,4 @@ +name = "youtube-js" +main = "bundle/cf-worker.js" +compatibility_date = "2024-09-23" +compatibility_flags = ["nodejs_compat"] From 37aae75f84eb013f3215f4f98a59278a64b812f9 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 20 Sep 2026 06:14:37 +0000 Subject: [PATCH 4/5] fix(cf-worker): explicitly enable workers_dev in Wrangler configuration Set `workers_dev = true` in `wrangler.toml` to silence Wrangler warning and explicitly enable routing on workers.dev during deployments. Co-authored-by: bxnxnxhzhdhdjdjjx-spec <315051886+bxnxnxhzhdhdjdjjx-spec@users.noreply.github.com> --- wrangler.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/wrangler.toml b/wrangler.toml index 06fa36c45..c4967a835 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -2,3 +2,4 @@ name = "youtube-js" main = "bundle/cf-worker.js" compatibility_date = "2024-09-23" compatibility_flags = ["nodejs_compat"] +workers_dev = true From 8261dca976905be2c432962a563eff485fad8629 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 20 Sep 2026 11:01:12 +0000 Subject: [PATCH 5/5] fix(cf-worker): explicitly enable workers_dev in Wrangler configuration Set `workers_dev = true` in `wrangler.toml` to silence Wrangler warning and explicitly enable routing on workers.dev during deployments. Co-authored-by: bxnxnxhzhdhdjdjjx-spec <315051886+bxnxnxhzhdhdjdjjx-spec@users.noreply.github.com>