> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brightdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 5 分钟快速入门：运行您的第一个浏览器会话

> 学习如何在 5 分钟内使用 Bright Data 浏览器 API 启动您的第一个浏览器会话。

本指南帮助您使用 Bright Data 浏览器 API **在 5 分钟内启动您的第一个真实浏览器会话**。\
它面向需要 **JavaScript 渲染、页面交互或动态内容**，而不需要管理浏览器或基础设施的开发者。

完成本指南后，您将能够：

* 验证您的浏览器 API 设置
* 启动一个实时浏览器会话
* 加载需要 JavaScript 渲染的网站

## 开始前需要的内容（1 分钟）

在开始之前，请确保您拥有：

* 一个 Bright Data 账户
* 一个活跃的**浏览器 API 区域**
* 有效的**浏览器 API 区域\*\*\*\*凭证**（用户名和密码）

您可以在 Bright Data 控制面板中浏览器 API 的**概览**选项卡中找到您的**凭证**。

如果您还没有创建浏览器 API，请先按照**创建您的第一个浏览器 API** 进行操作。

## 第 1 步：选择一个基于 JavaScript 的网站（30 秒）

选择一个需要 JavaScript 渲染的网站。

好的示例：

* [https://quotes.toscrape.com/js/](https://quotes.toscrape.com/js/)
* [https://www.nike.com](https://www.nike.com)
* [https://www.amazon.com](https://www.amazon.com)

确保 URL：

* 以 `https://` 开头
* 需要客户端渲染或类似用户的交互

## 第 2 步：了解浏览器 API 如何工作（30 秒）

浏览器 API 会代表您启动一个**真实的、基于云的浏览器会话**。

对于每个会话，Bright Data 会：

* 启动浏览器实例
* 应用逼真的指纹和请求头
* 处理代理路由和反机器人挑战
* 返回渲染的页面内容或会话输出

您无需管理浏览器、驱动程序或自动化基础设施。

## 第 3 步：启动您的第一个浏览器 API 会话（2 分钟）

将下面的占位符替换为您的实际值：

* USER:PASS
* YOUR\_TARGET\_URL

复制下面的示例代码片段之一，粘贴到您选择的 IDE 中。\
只需在替换参数后运行代码即可启动您的会话！

<Tabs>
  <Tab title="NodeJS">
    <CodeGroup>
      ```javascript Puppeteer theme={null}
      #!/usr/bin/env node
      const puppeteer = require('puppeteer-core');

      const AUTH = 'USER:PASS';
      const TARGET_URL = 'YOUR_TARGET_URL';

      async function main() {
          console.log('Connecting to Browser...');
          const browser = await puppeteer.connect({
              browserWSEndpoint: `wss://${AUTH}@brd.superproxy.io:9222`
          });

          const page = await browser.newPage();

          // Get debugging URL
          const client = await page.createCDPSession();
          const { frameTree: { frame } } = await client.send('Page.getFrameTree');
          const { url: inspectUrl } = await client.send('Page.inspect', {
              frameId: frame.id
          });
          console.log(`You can inspect this session at: ${inspectUrl}`);

          // Navigate to target
          await page.goto(TARGET_URL);

      	console.log(await page.content());
          await page.screenshot({ path: 'screenshot.png', fullPage: true });
          console.log('Navigation complete!');

          await browser.close();
      }

      main().catch(console.error);
      ```

      ```javascript Playwright theme={null}
      #!/usr/bin/env node
      const playwright = require('playwright');

      const AUTH = 'USER:PASS';
      const TARGET_URL = 'YOUR_TARGET_URL';

      async function main() {
          console.log('Connecting to Browser...');
          const browser = await playwright.chromium.connectOverCDP(
              `wss://${AUTH}@brd.superproxy.io:9222`
          );

          const page = await browser.newPage();

          // Get debugging URL
          const client = await page.context().newCDPSession(page);
          const { frameTree: { frame } } = await client.send('Page.getFrameTree');
              const { url: inspectUrl } = await client.send('Page.inspect', {
                  frameId: frame.id,
              });
          console.log(`You can inspect this session at: ${inspectUrl}.`);

          // Navigate to target
          await page.goto(TARGET_URL);

      	console.log(await page.content());
          await page.screenshot({ path: 'screenshot.png', fullPage: true });
          console.log('Navigation complete!');
          
          await browser.close();
      }

      main().catch(console.error);
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Python">
    <CodeGroup>
      ```python Playwright theme={null}
      #!/usr/bin/env python3
      import asyncio
      from playwright.async_api import async_playwright

      AUTH = 'USER:PASS'
      TARGET_URL = 'YOUR_TARGET_URL'

      async def main():
          print('Connecting to Browser...')
          
          async with async_playwright() as p:
              browser = await p.chromium.connect_over_cdp(
                  f'wss://{AUTH}@brd.superproxy.io:9222'
              )
              page = await browser.new_page()
              
              # Get debugging URL
              client = await page.context.new_cdp_session(page)
              frame_tree = await client.send('Page.getFrameTree')
              frame_id = frame_tree['frameTree']['frame']['id']
              inspect_result = await client.send('Page.inspect', {'frameId': frame_id})
              print(f"Debug URL: {inspect_result['url']}")
              
              # Navigate to target
              await page.goto(TARGET_URL)

      		print(await page.content())
              await page.screenshot(path='screenshot.png', full_page=True)
              print('Navigation complete!')
              
              await browser.close()

      if __name__ == '__main__':
          try:
              asyncio.run(main())
          except Exception as e:
              print(f'Error: {e}')
      ```

      ```python Selenium theme={null}
      #!/usr/bin/env python3
      from selenium.webdriver import Remote, ChromeOptions as Options
      from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection as Connection

      AUTH = 'USER:PASS'
      TARGET_URL = 'YOUR_TARGET_URL'

      def main():
          print('Connecting to Browser...')
          
          server_addr = f'https://{AUTH}@brd.superproxy.io:9515'
          connection = Connection(server_addr, 'goog', 'chrome')
          driver = Remote(connection, options=Options())
          
          def cdp(cmd, params={}):
              return driver.execute('executeCdpCommand', {
                  'cmd': cmd,
                  'params': params,
              })['value']
          
          try:
              # Get debugging URL
              frame_tree = cdp('Page.getFrameTree')
              frame_id = frame_tree['frameTree']['frame']['id']
              inspect_result = cdp('Page.inspect', {'frameId': frame_id})
              print(f"Debug URL: {inspect_result['url']}")
              
              # Navigate to target
              driver.get(TARGET_URL)

      		print(driver.page_source)
              driver.save_screenshot('screenshot.png')
              print('Navigation complete!')
          finally:
              driver.quit()

      if __name__ == '__main__':
          try:
              main()
          except Exception as e:
              print(f'Error: {e}')
      ```
    </CodeGroup>
  </Tab>
</Tabs>

此代码：

* 连接到远程浏览器会话
* 打印实时会话 URL
* 使用 JavaScript 完全渲染页面
* 打印页面的 HTML 内容
* 拍摄渲染页面的屏幕截图
* 关闭浏览器会话

## 第 4 步：查看响应（30 秒）

如果成功，您将收到：

* 完全渲染的 HTML 内容 + 屏幕截图
* 包含 JavaScript 生成的元素

如果页面内容与您在真实浏览器中看到的内容匹配，则您的浏览器 API 设置工作正常。

## 常见问题和快速修复（30 秒）

* **407 认证失败：** 认证缺失或无效\
  → 验证用户名和密码凭证
* **无效的 URL：** 所需的 URL 格式不正确\
  → 确认 TARGET\_URL 参数已更改为有效的 URL

## 您刚刚完成的任务

在 5 分钟内，您：

* 连接到远程无头浏览器会话
* 加载了一个 JavaScript 繁重的网站
* 检索了渲染的内容

您的浏览器 API 现在已准备好用于高级工作流程。

## 下一步

一旦您的第一个会话工作正常，您可以：

* 与页面交互（点击、滚动、输入）
* 运行多步浏览器工作流程
* 查看**浏览器 API 配置**了解高级控制
* 检查**故障排除**如果您遇到问题
