You need to enable JavaScript to run this app.
Volcano Engine Function as a Service

Volcano Engine Function as a Service

Copy page
Download PDF
Browser Session
Deploying Browser Session applications with a few clicks
Copy page
Download PDF
Deploying Browser Session applications with a few clicks
This topic describes how to deploy a Browser Session application with a few clicks by using the Application Center of Volcano Engine Function as a Service (veFaaS).​
Background information​
  • Application introduction​
  • veFaaS provides browser session capabilities. As a Browser-as-a-Service (BaaS) service, Browser Session directly provides browser instances for both internal and external users.​
  • You can obtain browser resources by using SDKs that support multiple programming languages, and then access the resources by using browser-related tools such as Playwright or Puppeteer, or upper-level services such as browser-use.​
  • Runtime​
  • Native runtime​
  • Associated cloud services​
warning​
The fees for using associated cloud services will be incurred. For billing details, refer to the billing documentation of the associated cloud services.​
  • browser-session-manager​
  • veFaaS: provides you with APIs for lifecycle management of browser instances.​
  • browser-pool​
  • veFaaS: runs browser instances.​
  • APIG: helps browser-session-manager manage browser instances.​
Prerequisites​
  • All the cloud services associated with the application have been activated.​
  • The VeFaaSFullAccess, APIGFullAccess, and STSAssumeRoleAccess policies have been attached to Identity and Access Management (IAM) users. If one of the preceding policies is not attached, contact the root user or the administrator for authorization. For specific operations, see Creating and authorizing users.​
  • An APIG instance of the serverless gateway type has been created. For detailed operations, please refer to Creating instances.​
  • If you use veFaaS for the first time, make sure that the cross-service authorization is complete. If the authorization is not complete, the cross-service authorization page will appear, which provides guidance on authorization.​
Procedure​
  1. Log in to the veFaaS console.​
  1. In the top navigation bar, select the target region.​
tip​
Only the China (Beijing) region supports the application.​
  1. In the left navigation bar, click App > My app.​
  1. On the My app page, click Create app.​
  1. On the Create application page, find the Browser Session template and click Create.​
  1. On the Create application page, specify the parameters of the application.​
  • Basic information​
  • ​
    Parameter​
    Description​
    Selected template​
    Displays the selected template. In this scenario, the template is Browser Session.​
    Name​
    Specify a custom name for the application based on the naming rule prompted by the system. You can also directly use the application name automatically generated by the system.​
    Description​
    Enter the description of the application. This parameter can be left empty.​
    IAM role​
    The Application Center provides the system default role ServerlessApplicationRole, which is granted permissions on some cloud resources that the Application Center needs to access.​
    • If your user roles do not contain this role, this role will be automatically added.​
    • If your user roles contain this role, the system will automatically detect whether all the policies required for the application are attached to this role. If a required policy is not attached, the console will display the name of the policy. You can click Add policy to add the policy.​
    warning​
    • Make sure that the IAMReadOnlyAccess policy is attached to IAM users. Otherwise, they will not be authorized to obtain information about the ServerlessApplicationRole role.​
    • If IAM users need to attach policies to the ServerlessApplicationRole role, make sure that the IAMFullAccess policy is attached to the IAM users.​
    Associated cloud services​
    Displays the names, activation status, and activation purposes of all the cloud services that the current application needs to use.​
    warning​
    For more information about possibly incurred fees and account balance requirements when you use the associated cloud services, see veFaaS billing and APIG billing.​
    ​
  • Resource allocation​
  • ​
    Parameter​
    Description​
    Browser resource pool configuration​
    ​
    Region​
    The region where the application and its associated cloud resources are located.​
    Function name​
    Specify a custom name for the function based on the naming rules prompted by the system. You can also directly use the function name automatically generated by the system.​
    Access configuration​
    ​
    API Gateway instance​
    Select the prepared APIG instance of the serverless type. APIG trigger-related resources will be automatically created for the APIG instance, including services, Upstreams, and routes.​
    API Access Key​
    Enter Volcano Engine access key information, which includes Access Key ID and Secret Access Key. For the obtaining method, see Access key management.​
    ​
  1. Click Confirm to create and deploy the application.​
  • You will be automatically redirected to the application details page. On the page, you can view the application deployment status and logs in real time.​
  1. After the application is deployed, click the access address below Access entrance details on the Application details tab to go to the interactive interface of your application.​
Use a browser​
You can obtain a browser instance by performing the preceding procedure. The following content describes how to use a browser.​
Browser operation tools​
Use a browser by using a browser operation tool such as Playwright and Puppeteer:​
  • Playwright​
  • ​
    from playwright.sync_api import sync_playwright​
    import websocket​
    import json​
    import requests​
    import time​
    ​
    def test_with_cdp():​
    # cdp_url = "ws://******.apigateway-cn-beijing.volceapi.com/v1/browsers/c400ec0c-37f3-4c01-a796-e406081b9678/devtools/browser/936c2835-3bf7-4a4b-99f5-7679088fed8e"​
    cdp_url = "https://******.apigateway-cn-beijing.volceapi.com/v1/browsers/9ebdaa2a-f075-48de-a92d-6cf23b1a0ded"​
    ​
    with sync_playwright() as playwright:​
    browser = playwright.chromium.connect_over_cdp(cdp_url)​
    print("Connected to browser via CDP")​
    ​
    context = browser.new_context()​
    page = context.new_page()​
    page.goto("https://toutiao.com")​
    print(page.url)​
    browser.close()​
    ​
    if __name__ == "__main__":​
    test_with_cdp()​
    ​
  • Output result:​
  • ​
    Connected to browser via CDP​
    https://www.toutiao.com/​
    ​
  • Puppeteer​
  • ​
    import asyncio​
    from pyppeteer import connect​
    ​
    async def test_with_cdp():​
    cdp_url = 'ws://******.apigateway-cn-beijing.volceapi.com/v1/browsers/02a2ce20-f8b7-46e3-9caa-f2023bd00c28/devtools/browser/f3f017c4-8e57-499d-8903-3e37b14e6c01'​
    ​
    try:​
    # Connect to the remote browser using CDP​
    browser = await connect({​
    'browserWSEndpoint': cdp_url,​
    'defaultViewport': None​
    })​
    print('Connected to browser via CDP')​
    ​
    # Create a new page​
    page = await browser.newPage()​
    ​
    # Navigate to toutiao.com​
    await page.goto('https://toutiao.com')​
    print(page.url)​
    ​
    # Close the browser connection​
    await browser.close()​
    except Exception as error:​
    print('Error:', str(error))​
    ​
    if __name__ == "__main__":​
    # Run the async function using asyncio.run()​
    asyncio.run(test_with_cdp()) ​
    ​
browser-use​
Use a browser instance provided by veFaaS in browser-use.​
​
from langchain_openai import ChatOpenAI​
from browser_use import Agent​
import asyncio​
from dotenv import load_dotenv​
from browser_use.browser.browser import Browser, BrowserConfig​
from browser_use.browser.context import BrowserContext​
​
load_dotenv()​
​
async def main():​
browser = Browser(​
config = BrowserConfig(​
cdp_url = "https://******.apigateway-cn-beijing.volceapi.com/v1/browsers/9ebdaa2a-f075-48de-a92d-6cf23b1a0ded"​
)​
)​
​
context = BrowserContext(​
browser=browser,​
)​
​
agent = Agent(​
task="Visit baidu.com and look up the latest Pico model.",​
llm=ChatOpenAI(model="gpt-4o"),​
browser_context=context​
)​
await agent.run()​
​
asyncio.run(main())​
​
Output result:​
​
➜ cdp git:(web) ✗ python run_browser_use.py​
INFO [browser_use] BrowserUse logging setup complete with level info​
INFO [root] Anonymized telemetry enabled. See https://docs.browser-use.com/development/telemetry for more information.​
/Users/bytedance/.pyenv/versions/3.12.8/lib/python3.12/site-packages/browser_use/agent/message_manager/views.py:59: LangChainBetaWarning: The function `load` is in beta. It is actively being worked on, so the API may change.​
value['message'] = load(value['message'])​
INFO [agent] 🚀 Starting task: Visit baidu.com and look up the latest Pico model.​
INFO [agent] 📍 Step 1​
INFO [browser] Connecting to remote browser via CDP https://xxxxxx.apigateway-cn-beijing.volceapi.com/v1/browsers/9ebdaa2a-f075-48de-a92d-6cf23b1a0ded​
INFO [agent] 🤷 Eval: Not applicable - starting fresh with a new task.​
INFO [agent] 🧠 Memory: Starting with a new task to find the latest model of 'pico' on baidu.com.​
INFO [agent] 🎯 Next goal: Navigate to baidu.com​
INFO [agent] 🛠️ Action 1/1: {"open_tab":{"url":"https://www.baidu.com"}}​
INFO [controller] 🔗 Opened new tab with https://www.baidu.com​
INFO [agent] 📍 Step 2​
INFO [agent] 👍 Eval: Success - Navigated to baidu.com successfully.​
INFO [agent] 🧠 Memory: Landed on Baidu, starting to search for the latest Pico model.​
INFO [agent] 🎯 Next goal: Enter 'Pico latest model' in the search box and perform the search.​
INFO [agent] 🛠️ Action 1/2: {"input_text":{"index":12,"text":"Pico latest model"}}​
INFO [agent] 🛠️ Action 2/2: {"click_element":{"index":8}}​
INFO [controller] ⌨️ Input Pico latest model into index 12​
INFO [agent] Something new appeared after action 1 / 2​
INFO [agent] 📍 Step 3​
INFO [agent] 👍 Eval: Success - Entered the search and received results regarding Pico.​
INFO [agent] 🧠 Memory: Searched for 'Pico latest model' on Baidu and found relevant information about the new models: PICO 4 Ultra and PICO Neo3 Enterprise Edition.​
INFO [agent] 🎯 Next goal: Summarize the findings and conclude the task.​
INFO [agent] 🛠️ Action 1/1: {"done":{"text":"The latest models of Pico are the PICO 4 Ultra and PICO Neo3 Enterprise Edition. PICO 4 Ultra includes 21 system updates and is marketed with enhanced mixed reality experiences. The PICO Neo3 Enterprise Edition targets enterprise markets with a new 6DoF optical positioning system, powered by Qualcomm Snapdragon XR2 chip, featuring 4K HD display and immersive audio components.","success":true}}​
INFO [agent] 📄 Result: The latest models of Pico are the PICO 4 Ultra and PICO Neo3 Enterprise Edition. PICO 4 Ultra includes 21 system updates and is marketed with enhanced mixed reality experiences. The PICO Neo3 Enterprise Edition targets enterprise markets with a new 6DoF optical positioning system, powered by Qualcomm Snapdragon XR2 chip, featuring 4K HD display and immersive audio components.​
INFO [agent] ✅ Task completed​
INFO [agent] ✅ Successfully​
​
Swagger​
For the visualized APIs of Swagger, refer to veFaaS Browser Session Manager API.​
API list​
​
Obtain the list of browser instances
Create a browser
Obtain browser information
Delete a browser
Obtain the JSON version of a browser
​
GET /browsers​
Return all browser instances grouped by pod.​
Response parameters​
  • 200 OK: The browser metadata of a pod in JSON format is returned.​
  • 500 Internal Server Error: A service error has occurred. Try again or contact your account manager of Volcano Engine to obtain technical support.​
Sample responses​
​
{​
"pod-name-1": {​
"podExpireAt": "2024-01-01T12:00:00Z",​
"browsers": [​
{​
"id": "browser-123",​
"pod_name": "pod-name-1",​
"status": "ready",​
"port": 9222,​
"cdp_url": "ws://localhost:9222/devtools/browser/abc123",​
"ws_url": "ws://localhost:9222/devtools/browser/abc123",​
"created_at": "2024-01-01T10:00:00Z",​
"expiration_time": "2024-01-01T11:00:00Z",​
"deleted_at": "",​
"options": {​
"enable_enhancement": true,​
"timeout": 300​
}​
}​
]​
}​
}​
​
​
​
Multilingual SDKs​
​
Python
Node.js
​
  • Installation command:​
  • ​
    pip install vefaas-browser-session​
    ​
  • Sample SDK:​
  • ​
    from vefaas_browser_session import Configuration, ApiClient, BrowsersApi​
    ​
    ​
    def create_browser():​
    browser_session_endpoint = 'https://sd1mt1m354gpj4to2lgh0.apigateway-cn-beijing.volceapi.com/v1'​
    ​
    try:​
    configuration = Configuration(host=browser_session_endpoint)​
    client = ApiClient(configuration=configuration)​
    api = BrowsersApi(client)​
    response = api.create_browser()​
    ​
    browser_id = response.id​
    cdp_url = response.cdp_url​
    ws_url = response.ws_url​
    ​
    print(f"✅ Browser created: {browser_id}")​
    print(f"🔗 CDP URL: {cdp_url}")​
    print(f"🌐 WebSocket: {ws_url}")​
    ​
    return cdp_url​
    except Exception as e:​
    print(f"❌ Error: {str(e)}")​
    return None​
    ​
    if __name__ == "__main__":​
    create_browser()​
    ​
  • The following sample code shows the expected response result:​
  • ​
    ➜ cdp git:(master) ✗ python python.py​
    ✅ Browser created: c5f7362d-055a-4905-934d-ff17d179cb59​
    🔗 CDP URL: https://sd1mt1m354gpj4to2lgh0.apigateway-cn-beijing.volceapi.com/v1/browsers/c5f7362d-055a-4905-934d-ff17d179cb59​
    🌐 WebSocket: ws://sd1mt1m354gpj4to2lgh0.apigateway-cn-beijing.volceapi.com/v0.1/browsers/c5f7362d-055a-4905-934d-ff17d179cb59/devtools/browser/cb87c79d-5371-4247-8145-be8eac5c0205?faasInstanceName=vefaas-2u02weu6-9e8t31v73p-d1uhb86366fga65vi7m0-sandbox​
    ​
  • ​
​
Last updated: 2026.08.19 14:06:07