A lightweight Node.js/TypeScript library to generate YouTube trusted sessions without using a browser. This project provides similar functionality to YouTube "Proof of Origin Token" (poToken) generators but with a more efficient implementation that doesn't require a browser.
This project is a TypeScript/Bun rewrite inspired by:
- YunzheZJU/youtube-po-token-generator - Original inspiration that generates a valid poToken with visitorData fetched from YouTube
- iv-org/youtube-trusted-session-generator - A Python-based YouTube session generator used by Invidious
This implementation provides similar functionality but is rewritten from the ground up in TypeScript and optimized for Bun as the runtime environment.
poToken (Proof of Origin Token) is an attestation token generated by a complex anti-robot verification system created by Google named BotGuard/DroidGuard. It is used to confirm that requests to YouTube are coming from genuine clients.
These identity tokens (poToken and visitor_data) will make your YouTube session more easily traceable by YouTube because they are tied to a unique identifier. The benefit is that they allow applications to access YouTube content that would otherwise be blocked.
- Generate YouTube visitor data and poToken
- No browser dependency
- Lightweight and fast
- Multi-threaded token generation
- Easy to use
- One-shot mode for direct token retrieval
- API mode for programmatic access
- Continuous token refreshing every 30 seconds
- HTTP server with web interface and API endpoints
- Automatic token management
- Node.js >= 18.0
- Bun (recommended for best performance)
# Clone the repository
git clone https://github.com/your-username/youtube-trusted-session-generator.git
cd youtube-trusted-session-generator
# Install dependencies
bun installIn normal mode, the generator will:
- Start an HTTP server on port 3000 (configurable via PORT env variable)
- Generate tokens immediately
- Automatically refresh tokens every 30 seconds (configurable via REFRESH_INTERVAL env variable)
- Provide a web interface and API endpoints
bun startAccess the web interface by opening a browser and navigating to:
http://localhost:3000/
The interface allows you to:
- View current tokens
- Force update tokens with a single click
- See success and error messages
GET /- Web interfaceGET /token- Get current tokensGET /update- Force update tokens (returns success message)
The /update endpoint will return a success message when tokens are updated:
{
"status": "success",
"code": 200,
"message": "Tokens have been successfully updated",
"instructions": "Please get the updated tokens from the /token endpoint"
}After receiving this success message, you should get the updated tokens from the /token endpoint.
Run the generator once and get tokens directly:
bun start --oneshotThis will output the tokens in JSON format:
{
"visitorData": "visitor_data_string",
"poToken": "po_token_string"
}The generator returns an object with the following structure:
{
visitorData: "string", // YouTube visitor data
poToken: "string" // YouTube poToken
}- Tokens are automatically refreshed every 30 seconds in normal mode (configurable via REFRESH_INTERVAL env variable)
- Tokens can be force-refreshed using the
/updateendpoint - The API provides a
forceUpdateoption to bypass caching - Multi-threading is used for faster token generation
The library includes built-in error handling and will throw errors for:
- Network connection issues
- Invalid responses from YouTube
- Parsing errors
You can use this library with Invidious by:
- Running the generator in either one-shot or normal mode
- Getting the poToken and visitorData values
- Adding these values to your Invidious config.yaml:
po_token: XXX visitor_data: XXX
- Restarting Invidious
You can also use this library with any other application that needs to communicate with YouTube's API:
- Run the generator in normal mode
- Use the API endpoint to fetch updated tokens when needed
- Include the tokens in your YouTube API requests
- Original implementation: YunzheZJU/youtube-po-token-generator
- Inspiration: iv-org/youtube-trusted-session-generator
This project is licensed under the MIT License - see the LICENSE file for details.