{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Automation Examples (CDP)","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"automation-examples-cdp","__idx":0},"children":["Automation Examples (CDP)"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Once your agent has started a MoreLogin profile via the Skill, it receives a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["debugPort"]},". This port can be used to connect directly to the browser instance using ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["CDP (Chrome DevTools Protocol)"]},", bypassing the need for WebDriver."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can instruct your Hermes or OpenClaw agent to write and execute scripts using the following patterns."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"1-connecting-with-puppeteer","__idx":1},"children":["1. Connecting with Puppeteer"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"// Get debugPort from:\n// openclaw morelogin browser status --env-id <envId>\nconst puppeteer = require('puppeteer-core');\n\nasync function main() {\n  const browser = await puppeteer.connect({\n    browserURL: 'http://127.0.0.1:9222', // replace 9222 with actual debugPort\n    defaultViewport: null\n  });\n\n  const pages = await browser.pages();\n  const page = pages[0];\n  await page.goto('https://example.com');\n  \n  // Scrape data or perform actions\n  const title = await page.title();\n  console.log('Title:', title);\n  \n  // NOTE: Do not call browser.close() unless you want to destroy the MoreLogin process\n  await browser.disconnect();\n}\nmain();\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"2-form-fill-and-submit","__idx":2},"children":["2. Form Fill and Submit"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const puppeteer = require('puppeteer-core');\n\nasync function main() {\n  const browser = await puppeteer.connect({\n    browserURL: 'http://127.0.0.1:<debugPort>'\n  });\n  \n  const page = await browser.newPage();\n  await page.goto('https://example.com/login');\n  \n  // Fill form\n  await page.type('#username', 'myuser');\n  await page.type('#password', 'mypassword');\n  \n  // Click submit\n  await page.click('button[type=\"submit\"]');\n  \n  // Wait for navigation\n  await page.waitForNavigation();\n  \n  // Verify login\n  const isLoggedIn = await page.$('.user-profile');\n  console.log('Login successful:', !!isLoggedIn);\n  \n  await browser.disconnect();\n}\nmain();\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"3-data-scraping","__idx":3},"children":["3. Data Scraping"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const puppeteer = require('puppeteer-core');\nconst fs = require('fs');\n\nasync function main() {\n  const browser = await puppeteer.connect({\n    browserURL: 'http://127.0.0.1:<debugPort>'\n  });\n  \n  const page = await browser.newPage();\n  await page.goto('https://example.com/products');\n  \n  // Scrape data\n  const products = await page.evaluate(() => {\n    return Array.from(document.querySelectorAll('.product')).map(el => ({\n      name: el.querySelector('.name')?.textContent,\n      price: el.querySelector('.price')?.textContent,\n      url: el.querySelector('a')?.href\n    }));\n  });\n  \n  // Save to file\n  fs.writeFileSync('products.json', JSON.stringify(products, null, 2));\n  console.log(`Scraped ${products.length} products`);\n  \n  await browser.disconnect();\n}\nmain();\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"4-multi-tab-operations","__idx":4},"children":["4. Multi-Tab Operations"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const puppeteer = require('puppeteer-core');\n\nasync function main() {\n  const browser = await puppeteer.connect({\n    browserURL: 'http://127.0.0.1:<debugPort>'\n  });\n  \n  // Open multiple tabs\n  const page1 = await browser.newPage();\n  const page2 = await browser.newPage();\n  \n  await page1.goto('https://example.com');\n  await page2.goto('https://github.com');\n  \n  // Parallel operations\n  await Promise.all([\n    page1.screenshot({ path: 'page1.png' }),\n    page2.screenshot({ path: 'page2.png' })\n  ]);\n  \n  console.log('Screenshots completed');\n  \n  await browser.disconnect();\n}\nmain();\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"troubleshooting","__idx":5},"children":["Troubleshooting"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Error: ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["connect ECONNREFUSED"]}]},": Ensure the profile is running and that the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["debugPort"]}," is correct. You can verify ports using ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["lsof -i :<port>"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Browser Crashes on Connection"]},": Use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["puppeteer-core"]}," instead of ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["puppeteer"]},", and ensure you call ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["browser.disconnect()"]}," instead of ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["browser.close()"]}," when your script finishes."]}]}]},"headings":[{"value":"Automation Examples (CDP)","id":"automation-examples-cdp","depth":1},{"value":"1. Connecting with Puppeteer","id":"1-connecting-with-puppeteer","depth":2},{"value":"2. Form Fill and Submit","id":"2-form-fill-and-submit","depth":2},{"value":"3. Data Scraping","id":"3-data-scraping","depth":2},{"value":"4. Multi-Tab Operations","id":"4-multi-tab-operations","depth":2},{"value":"Troubleshooting","id":"troubleshooting","depth":2}],"frontmatter":{"seo":{"title":"Automation Examples (CDP)"}},"lastModified":"2026-05-13T03:54:13.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/skills/automation","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}