--- title: "Python" url: https://docs.catalyst.zoho.com/en/smartbrowz/help/headless/implementation/function-stack/python/ description: "Connect with a remote browser in the Catalyst cloud environment in a headless mode using an automation library of your choice." last_updated: 2025-10-09T16:11:25Z service: SmartBrowz type: general --- # Connect to Headless with Python Function Stack In this section you will find the required scripts to connect to headless using the Python function stack with a browser automation library of your preference: ### Puppeteer #### Using Puppeteer Without SmartBrowz ```python import asyncio from puppeteer import launch async def main(): browser = await launch() page = await browser.newPage() await page.goto('http://example.com') await page.screenshot({'path': 'example.png'}) await browser.close() asyncio.get_event_loop().run_until_complete(main()) ``` #### Using Puppeteer With SmartBrowz ```python import asyncio import pyppeteer async def main(): # Replace puppeteer.launch with pyppeteer.launcher.connect browser = await pyppeteer.launcher.connect( browserWSEndpoint='YOUR_CDP_ENDPOINT' ) # The rest of your code remains the same page = await browser.newPage() await page.goto("https://example.com") await page.screenshot(path="screenshot.png") await browser.close() asyncio.get_event_loop().run_until_complete(main()) ``` > **Note:** Copy the CDP Endpoint from the console and paste it in line "**6**" when you implement this code. ### Playwright #### Using Playwright Without SmartBrowz ```python from playwright.sync_api import sync_playwright def run(playwright): chrome = playwright.chrome browser = chrome.launch() page = browser.new_page() page.goto("https://example.com") browser.close() with sync_playwright() as playwright: run(playwright) ``` #### Using Playwright With SmartBrowz ```python import asyncio from playwright.async_api import async_playwright async def run(playwright): # Replace playwright.chromium.launch with connect_over_cdp browser = playwright.chromium.connect_over_cdp("YOUR_CDP_ENDPOINT") # The rest of the code remians the same context = await browser.new_context() page = await context.new_page() await page.goto("https://example.com") await page.screenshot(path="screenshot.png") await browser.close() async def main(): async with async_playwright() as playwright: await run(playwright) asyncio.run(main()) ``` > **Note:** Copy the CDP Endpoint from the console and paste it in line "**5**" when you implement this code. ### Selenium #### Using Selenium Without SmartBrowz ```python from selenium import webdriver from PIL import Image driver = webdriver.Chrome(executable_path = "path\\to\\chromedriver.exe") url = "https://example.com/" driver.get(url) driver.save_screenshot(‘ss.png’) screenshot = Image.open(‘ss.png’) driver.close() ``` #### Using Selenium With SmartBrowz ```python import asyncio from selenium import webdriver from selenium.webdriver.chrome.options import Options async def index(): options = Options() options.add_argument("--disable-extensions") options.add_argument("--no-sandbox") options.add_argument('--headless') options.add_argument('--disable-dev-shm-usage') # Change webdriver.Chrome with webdriver.Remote driver = webdriver.Remote( command_executor='YOUR_WEBDRIVER_ENDPOINT', options=options ) #The rest of your code remains the same driver.get("https://example.com") driver.save_screenshot("screenshot.png") driver.close() async def my_async_function(): await index() # call my_async_function asyncio.run(my_async_function()) ``` > **Note:** Copy the Webdriver Endpoint from the console and paste it in line "**13**" when you implement this code.