Skip to content

Commit

Permalink
fix(examples): Use BgUtils to generate pot [skip ci]
Browse files Browse the repository at this point in the history
+ Improve readme.
  • Loading branch information
LuanRT committed Aug 26, 2024
1 parent 367a6f7 commit d89909a
Show file tree
Hide file tree
Showing 5 changed files with 386 additions and 103 deletions.
68 changes: 13 additions & 55 deletions examples/browser/README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,19 @@
# Browser Usage Example

YouTube.js works in the browser!

## Usage

# Browser Usage
To use YouTube.js in the browser you must proxy requests through your own server. You can see our simple reference implementation in Deno in `examples/browser/proxy/deno.ts`.

We'll use our own fetch implementation to proxy requests through our server. This is a simple example, but you can use any fetch implementation you want.

```ts
import { Innertube } from "youtubei.js/web.bundle.min";

const yt = await Innertube.create({
fetch: async (input, init) => {
// url
const url = typeof input === 'string'
? new URL(input)
: input instanceof URL
? input
: new URL(input.url);

// transform the url for use with our proxy
url.searchParams.set('__host', url.host);
url.host = 'localhost:8080';
url.protocol = 'http';

const headers = init?.headers
? new Headers(init.headers)
: input instanceof Request
? input.headers
: new Headers();

// now serialize the headers
url.searchParams.set('__headers', JSON.stringify([...headers]));

// copy over the request
const request = new Request(
url,
input instanceof Request ? input : undefined,
);
## Example
**NOTE**: Build the library before running the examples.

headers.delete('user-agent');
Web application:

// fetch the url
return fetch(request, init ? {
...init,
headers
} : {
headers
});
},
cache: new UniversalCache(),
});
```shell
cd examples/browser/web
npm install
npm run dev
```

After that, you can use the library as normal.

## Example

We've got a full example in `examples/browser/web` using vite.
Proxy:
```shell
deno run --allow-net --allow-read examples/browser/proxy/deno.ts
```
283 changes: 283 additions & 0 deletions examples/browser/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/browser/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"vite": "^3.0.0"
},
"dependencies": {
"bgutils-js": "^1.1.0",
"shaka-player": "^4.3.8"
}
}
}
Loading

0 comments on commit d89909a

Please sign in to comment.