From 5dbf63b227811519397d11d230ebfb3a5964b4cb Mon Sep 17 00:00:00 2001 From: maspend Date: Mon, 30 Nov 2026 20:53:39 +0700 Subject: [PATCH] =?UTF-8?q?Pend=20Proxy=20v1:=20isolated=20proxy=20browser?= =?UTF-8?q?=20on=20Cloudflare=20Workers=20=E2=80=94=20editable=20device=20?= =?UTF-8?q?+=20browser=20profiles,=20per-profile=20cookie=20jars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + README.md | 52 ++++++++++ worker.js | 271 ++++++++++++++++++++++++++++++++++++++++++++++++++ wrangler.toml | 3 + 4 files changed, 328 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 worker.js create mode 100644 wrangler.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..552f221 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +*.log diff --git a/README.md b/README.md new file mode 100644 index 0000000..e0b5a21 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# Pend Proxy + +Isolated proxy browser on Cloudflare Workers. Browse any site through the Worker +with a device + browser of your choice — each profile is its own isolated session +with its own cookie jar. + +## Features + +- **Device & browser profiles** — create/edit profiles: device name, browser + (Chrome / Firefox / Safari / Edge), version, OS. The User-Agent is auto-built + from your choices and is fully editable. +- **Isolated sessions** — every profile keeps its own cookies (stored in your + browser's localStorage, per profile). Switching profiles = a clean, separate + session. "Clear cookies" wipes one profile only. +- **In-page navigation** — links clicked inside the viewer stay inside the proxy. +- **Private-host guard** — localhost / private IPs are blocked server-side. + +## Deploy (Cloudflare Workers) + +1. Create a Worker in the Cloudflare dashboard (Workers & Pages → Create). +2. Paste `worker.js` as the Worker code and Deploy. No bindings needed. +3. Open the Worker's URL. Free tier is enough. + +Or with Wrangler (needs a Cloudflare API token): + +```sh +npx wrangler deploy +``` + +## Local test + +```sh +npm install +npx wrangler dev worker.js --port 8787 +# open http://127.0.0.1:8787/ +``` + +## How it works + +- `GET /` serves the UI (embedded in the Worker). +- `POST /api/fetch` `{ url, ua, cookies }` → the Worker fetches the URL with + your profile's User-Agent + that profile's cookies, and returns + `{ status, finalUrl, contentType, body, setCookies }`. +- The UI stores each profile's cookies separately and sends only that + profile's jar with each request. + +## Honest limits + +- Simple proxy: pages render, but heavy JS apps (YouTube, logged-in apps) may + not fully work through it — API calls from inside the page don't all route + through the proxy. +- A datacenter IP (Cloudflare's) can still be bot-checked by some sites. diff --git a/worker.js b/worker.js new file mode 100644 index 0000000..1598541 --- /dev/null +++ b/worker.js @@ -0,0 +1,271 @@ +// Pend Proxy — isolated proxy browser on Cloudflare Workers. +// Each profile = its own device + browser (User-Agent) + its own cookie jar. +// The browser keeps cookie jars in localStorage; the Worker only fetches. + +const UI_HTML = ` + +Pend Proxy + + +

Pend Proxy — isolated sessions, your device, your browser

+
+ + + + +
+
Ready. Pick a profile, enter a URL, hit Go. Each profile is an isolated session with its own cookies.
+
+ +
+
+ +`; + +function isBlockedHost(hostname) { + const h = hostname.toLowerCase(); + if (h === 'localhost' || h.endsWith('.localhost')) return true; + if (/^(127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|0\.0\.0\.0|::1)/.test(h)) return true; + return false; +} + +async function handleFetch(request) { + let body; + try { body = await request.json(); } catch { return json({ error: 'Invalid JSON body' }, 400); } + const url = (body.url || '').trim(); + const ua = (body.ua || '').trim().slice(0, 512); + const cookies = body.cookies && typeof body.cookies === 'object' ? body.cookies : {}; + if (!/^https?:\/\//i.test(url)) return json({ error: 'Only http(s) URLs are allowed' }, 400); + let parsed; + try { parsed = new URL(url); } catch { return json({ error: 'Invalid URL' }, 400); } + if (isBlockedHost(parsed.hostname)) return json({ error: 'Blocked: private/local hosts are not allowed' }, 403); + + const headers = new Headers(); + if (ua) headers.set('User-Agent', ua); + headers.set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8'); + headers.set('Accept-Language', 'en-US,en;q=0.9'); + const cookieHeader = Object.entries(cookies).map(([k, v]) => k + '=' + v).join('; '); + if (cookieHeader) headers.set('Cookie', cookieHeader); + + let res; + try { + res = await fetch(url, { headers, redirect: 'follow' }); + } catch (e) { + return json({ error: 'Fetch failed: ' + (e && e.message ? e.message : String(e)) }, 502); + } + const contentType = res.headers.get('content-type') || ''; + const setCookies = []; + if (typeof res.headers.getSetCookie === 'function') { + setCookies.push(...res.headers.getSetCookie()); + } else { + const sc = res.headers.get('set-cookie'); + if (sc) setCookies.push(sc); + } + const text = await res.text(); + return json({ + status: res.status, + finalUrl: res.url, + contentType, + bytes: text.length, + setCookies, + body: text.slice(0, 2_000_000), + }); +} + +function json(obj, status = 200) { + return new Response(JSON.stringify(obj), { + status, + headers: { 'content-type': 'application/json; charset=utf-8' }, + }); +} + +export default { + async fetch(request) { + const url = new URL(request.url); + if (request.method === 'POST' && url.pathname === '/api/fetch') return handleFetch(request); + if (request.method === 'GET' && url.pathname === '/') { + return new Response(UI_HTML, { headers: { 'content-type': 'text/html; charset=utf-8' } }); + } + return new Response('Not found', { status: 404 }); + }, +}; diff --git a/wrangler.toml b/wrangler.toml new file mode 100644 index 0000000..3aa2e5e --- /dev/null +++ b/wrangler.toml @@ -0,0 +1,3 @@ +name = "pend-proxy" +main = "worker.js" +compatibility_date = "2026-11-30"