{"id":22400959,"url":"https://github.com/samdenty/cors-bypass","last_synced_at":"2025-07-31T15:31:34.692Z","repository":{"id":57209563,"uuid":"164337965","full_name":"samdenty/cors-bypass","owner":"samdenty","description":"Bypass the browsers CORS restrictions, without needing to setup a server-side proxy. ","archived":false,"fork":false,"pushed_at":"2019-01-07T18:22:32.000Z","size":147,"stargazers_count":25,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-26T21:15:09.811Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://cors-bypass.netlify.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samdenty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-06T19:20:16.000Z","updated_at":"2023-06-30T22:28:29.000Z","dependencies_parsed_at":"2022-09-01T07:51:08.723Z","dependency_job_id":null,"html_url":"https://github.com/samdenty/cors-bypass","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdenty%2Fcors-bypass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdenty%2Fcors-bypass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdenty%2Fcors-bypass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdenty%2Fcors-bypass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samdenty","download_url":"https://codeload.github.com/samdenty/cors-bypass/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228258291,"owners_count":17892657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T08:17:36.831Z","updated_at":"2024-12-05T08:17:37.603Z","avatar_url":"https://github.com/samdenty.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cors-bypass\n\nBypass the browsers CORS restrictions, **without needing to setup a server-side proxy**. [Demo](https://cors-bypass.netlify.com/)\n\n- Allows you to make HTTP requests from a HTTPS page\n- 100% coverage for the [`WebSocket` API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) spec\n\n## How does this module work?\n\nIt uses [`postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) to send cross-domain events, which is used to provide mock HTTP APIs (`fetch`, `WebSocket`, `XMLHTTPRequest` etc.). [Simplified version](https://stackoverflow.com/a/44943661/5269570)\n\n## How do I use it\n\nTheres three components to this module: the `Server`, `Adapter` and `Client`.\n\n### Server\n\nSimply serve a HTML file on a domain from which you want to **make requests from** (HTTP domain for example), with the following (use a bundler like [Webpack](https://webpack.js.org), [Parcel](https://parceljs.org) etc):\n\n```typescript\nimport { Server } from 'cors-bypass'\n\nconst server = new Server()\n```\n\n\u003cdetails\u003e\u003csummary\u003eWithout a bundler\u003c/summary\u003e\n\u003cp\u003e\n\n```html\n\u003cbody\u003e\n  \u003cscript src=\"./node_modules/cors-bypass/lib/server.bundle.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n```\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n### Adapter\n\nNext you need a HTML file from the domain that **will make requests** (your web app's domain). The adapter is in control of forwarding requests from a client located on _any page of your site_, to the server (using a [`BroadcastChannel`](https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel)).\n\n```typescript\nimport { Adapter } from 'cors-bypass'\nconst adapter = new Adapter()\n```\n\n\u003cdetails\u003e\u003csummary\u003eWithout a bundler\u003c/summary\u003e\n\u003cp\u003e\n\n```html\n\u003cbody\u003e\n  \u003cscript src=\"./node_modules/cors-bypass/lib/adapter.bundle.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n```\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n### Client\n\nAs long as the Adapter is running in a different tab (on the same domain as the client), you will be able to make requests.\n\n```typescript\n// Located somewhere on https://your-site.com\nimport * as BypassCors from 'cors-bypass'\n\nconst client = new BypassCors.Client()\n\nawait client.getServer() // null - no server connected yet\nawait client.openServerInNewTab({\n  serverUrl: 'http://random-domain.com/server.html',\n  adapterUrl: 'https://your-site.com/adapter.html'\n})\nawait client.getServer() // { id: 123, url: 'http://random-domain.com/server.html' }\n\n// Create a WebSocket (websocket is loaded in the server tab, but it's API is available on this page)\nconst ws = new BypassCors.WebSocket('ws://echo.websocket.org')\nws.onopen = () =\u003e ws.send('hello')\nws.onmessage = ({ data }) =\u003e console.log('received', data)\n```\n\n## Use cases\n\n### HTTP requests for Offline PWAs\n\nAs using a Service Worker require HTTPS, it's impossible to connect to local devices which only support HTTP.\n\nUsing this module does requires the user to open an extra window, but it lets you bypass cors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdenty%2Fcors-bypass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamdenty%2Fcors-bypass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdenty%2Fcors-bypass/lists"}