This feature allows you to dynamically mount Tampermonkey scripts to enhance AI Studio's model list, supporting custom model injection and configuration management. The system uses Playwright native network interception technology to parse the model list directly from the Tampermonkey script, ensuring 100% reliability and frontend-backend data consistency.
- ✅ Playwright Native Interception - Uses Playwright route interception, unaffected by browser security policies
- ✅ Double Assurance Mechanism - Network interception + Script injection, ensuring failsafe operation
- ✅ Direct Script Parsing - Automatically parses model lists from the Tampermonkey script, no extra config file needed
- ✅ Frontend-Backend Sync - Frontend and backend use the same model data source
- ✅ Auto Adaptation - Automatically fetches new model lists when the script updates
- ✅ Silent Failure - Silently skips if the script file does not exist, without affecting main functions
Add the following configuration to your .env file:
# Whether to enable script injection feature
ENABLE_SCRIPT_INJECTION=true
# Tampermonkey script file path (relative to project root)
# Model data is parsed directly from this script file
USERSCRIPT_PATH=browser_utils/more_models.jsTampermonkey Script → Playwright Network Interception (Backend) + Script Injection (Frontend) → API Sync
- Backend (Playwright): Intercepts
/api/modelsrequests at the network layer, directly injecting parsed model data. This is the core mechanism ensuring reliability. - Frontend (Browser): Auxiliarily injects the original Tampermonkey script into the page to ensure UI consistency.
- Sync: Frontend and backend use the same script data source, keeping completely consistent.
- 🎯 High Reliability - Unaffected by browser security restrictions
- ⚡ Earlier Interception - Intercepts at network level, superior to JavaScript injection
- 🛡️ Double Assurance - Network interception + Script injection
- 🔄 Single Data Source - Tampermonkey script is the sole source of model definitions
Ensure set in .env file:
ENABLE_SCRIPT_INJECTION=truePlace your Tampermonkey script at browser_utils/more_models.js (or the path you specified in USERSCRIPT_PATH).
Start AI Studio Proxy service normally, the system will automatically handle injection and parsing.
- Frontend: Injected models can be seen on the AI Studio page
- API: Full list containing injected models can be obtained via
/v1/modelsendpoint
After enabling script injection, you will see output similar to this in the logs:
# Network interception related logs
Setting up network interception and script injection...
Successfully set up model list network interception
Successfully parsed 6 models from Tampermonkey script
# Logs during model list response processing
Captured potential model list response from: https://alkalimakersuite.googleapis.com/...
Added 6 injected models to API model list
Successfully parsed and updated model list. Total models parsed: 12
# Example of parsed models
👑 Kingfall (Script v1.6)
✨ Gemini 1.5 Pro (Script v1.6)
🦁 Goldmane (Script v1.6)
- Check File Path - Ensure
USERSCRIPT_PATHpoints to an existing file - Check File Permissions - Ensure script file is readable
- Check Logs - Check detailed error messages
- Script Format - Ensure
MODELS_TO_INJECTarray format in Tampermonkey script is correct - Required Fields - Ensure each model has
nameanddisplayNamefields - JavaScript Syntax - Ensure script file is valid JavaScript format
If you encounter issues, you can temporarily disable script injection:
ENABLE_SCRIPT_INJECTION=falseYou can use a different script file:
USERSCRIPT_PATH=custom_scripts/my_script.jsThe system automatically parses version information in the script, maintaining consistent display effects with the Tampermonkey script, including emojis and version identifiers.
- Restart to Take Effect - Service restart is needed after script file update
- Browser Cache - If model list doesn't update, try refreshing page or clearing browser cache
- Compatibility - Ensure your Tampermonkey script is compatible with current AI Studio page structure
- Core Implementation -
browser_utils/initialization/network.pyimplements Playwright network interception logic. - Script Injection -
browser_utils/initialization/scripts.pyis responsible for injecting script into browser context. - Script Management -
browser_utils/script_manager.pyis responsible for loading and parsing script content. - Script Parsing -
browser_utils/operations_modules/parsers.pyis responsible for extracting model data from the script.