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

# Open browser

> Open the browser in the specified box. If the browser is already open, repeated calls will not open a new browser.



## OpenAPI

````yaml post /boxes/{boxId}/browser/open
openapi: 3.0.0
info:
  title: GBOX Open API
  description: GBOX Open API Documentation
  version: '1.0'
  contact: {}
servers:
  - url: https://gbox.ai/api/v1
    description: Production Server
security: []
tags: []
paths:
  /boxes/{boxId}/browser/open:
    post:
      tags:
        - Browser
      summary: Open browser
      description: >-
        Open the browser in the specified box. If the browser is already open,
        repeated calls will not open a new browser.
      operationId: BrowserController_open
      parameters:
        - name: boxId
          required: true
          in: path
          description: Box ID
          schema:
            example: c9bdc193-b54b-4ddb-a035-5ac0c598d32d
            type: string
      requestBody:
        required: true
        description: Browser open configuration
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BrowserOpenConfig'
      responses:
        '200':
          description: Successfully opened the browser, return the CDP url
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BrowserOpenResult'
      security:
        - bearer: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import GboxSDK from "gbox-sdk";
            import { chromium } from "playwright";

            const gboxSDK = new GboxSDK({
              apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
            });

            async function main() {
              const box = await gboxSDK.create({ type: "linux" });

              const result = await box.browser.open({
                maximize: true,
                showControls: false,
              })

              const browser = await chromium.connectOverCDP(result.cdpUrl);

              // Use the browser as usual
              const context = await browser.newContext();
              const page = await context.newPage();
              await page.goto("https://example.com");

              // Perform actions on the page
              console.log(await page.title());

              await box.browser.close()
            }

            main();
        - lang: Python
          source: |-
            import os
            import asyncio
            from gbox_sdk import GboxSDK
            from playwright.async_api import async_playwright

            async def main():
                gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])

                box = gbox_sdk.create(type="linux")

                # Open browser with configuration
                result = await box.browser.open(
                    maximize=True,
                    showControls=False
                )

                async with async_playwright() as p:
                    browser = await p.chromium.connect_over_cdp(result.cdp_url)

                    # Use the browser as usual
                    context = await browser.new_context()
                    page = await context.new_page()
                    await page.goto("https://example.com")

                    # Perform actions on the page
                    title = await page.title()
                    print(title)

                    # Close the browser
                    await browser.close()

                await box.browser.close()

            if __name__ == "__main__":
                asyncio.run(main())
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/gbox/gbox-sdk-go\"\n)\n\nfunc main() {\n\tgboxSDK := gbox.NewGboxSDK(os.Getenv(\"GBOX_API_KEY\"))\n\n\tbox, err := gboxSDK.Create(context.Background(), gbox.CreateOptions{Type: \"linux\"})\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to create linux box: %v\", err)\n\t}\n\n\tresult, err := box.Browser.Open(context.Background(), &gbox.BrowserOpenConfig{\n\t\tMaximize:     boolPtr(true),\n\t\tShowControls: boolPtr(false),\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to open browser: %v\", err)\n\t}\n\n\tfmt.Printf(\"Browser opened successfully\\n\")\n\tfmt.Printf(\"CDP URL: %s\\n\", result.CdpUrl)\n\n\t// You can use this CDP URL with Chrome DevTools Protocol libraries\n\t// like github.com/chromedp/chromedp or github.com/go-rod/rod\n\n\terr = box.Browser.Close(context.Background())\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to close browser: %v\", err)\n\t}\n}\n\nfunc boolPtr(b bool) *bool {\n\treturn &b\n}"
components:
  schemas:
    BrowserOpenConfig:
      type: object
      properties:
        showControls:
          type: boolean
          description: >-
            Whether to show the browser's minimize, maximize and close buttons.
            Default is true.
          example: true
          default: true
          title: ShowControls
        maximize:
          type: boolean
          description: Whether to maximize the browser window.
          example: false
          title: Maximize
        size:
          type: string
          description: >-
            The window size, format: <width>x<height>. If not specified, the
            browser will open with the default size. If both `maximize` and
            `size` are specified, `maximize` will take precedence.
          example: 1024x768
          title: Size
      title: Browser Open Config
      description: Browser open config
    BrowserOpenResult:
      type: object
      properties:
        cdpUrl:
          type: string
          description: >-
            The CDP url. You can use this URL with CDP libraries like
            puppeteer/playwright/etc.
          example: >-
            https://gbox.ai/api/v1/boxes/031df7cd-baa4-4d50-92ee-4ceaf04b0905/browser/connect/
          title: CdpUrl
      title: Browser Open Result
      description: Browser open result
      required:
        - cdpUrl
  securitySchemes:
    bearer:
      scheme: bearer
      bearerFormat: JWT
      type: http
      description: >-
        Enter your API Key in the format: Bearer <token>. Get it from
        https://gbox.ai

````