{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Node.js Puppeteer オートメーション","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":"nodejs-puppeteer-オートメーション","__idx":0},"children":["Node.js Puppeteer オートメーション"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["これは、ローカル API 経由で MoreLogin プロファイルを開始し、",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://pptr.dev/"},"children":["Puppeteer"]}," を使用してそれに接続する方法を示す、完全な実行可能な Node.js サンプルです。"]},{"$$mdtype":"Tag","name":"blockquote","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["注意"]},": これには、MoreLogin クライアントが実行されており、ローカルでログインしている必要があります。"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"前提条件","__idx":1},"children":["前提条件"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"npm install puppeteer axios\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"スクリプト例","__idx":2},"children":["スクリプト例"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const puppeteer = require(\"puppeteer\");\nconst axios = require(\"axios\");\n\n// Start a browser profile and return the debug port\nasync function getDebugPort(profileId) {\n  const url = `http://localhost:40000/api/env/start`;\n  \n  try {\n    const response = await axios.post(url, { envId: profileId });\n    if (response.data.code === 0) {\n      return response.data.data.debugPort;\n    } else {\n      console.error(`API Error: ${response.data.msg}`);\n      return -1;\n    }\n  } catch (error) {\n    console.error(`Request Failed: ${error.message}`);\n    return -1;\n  }\n}\n\n(async function run() {\n  // Replace with your actual profile ID\n  const profileId = \"1907751741233373184\"; \n  \n  const port = await getDebugPort(profileId);\n  if (port <= 0) {\n    console.log(\"Failed to start the environment\");\n    return;\n  }\n\n  console.log(`Connected to port: ${port}`);\n  \n  // Connect Puppeteer to the running instance via CDP\n  const browserURL = `http://127.0.0.1:${port}`;\n  const browser = await puppeteer.connect({ browserURL });\n  \n  // Create a new tab and automate\n  const page = await browser.newPage();\n  await page.goto(\"https://google.com\");\n  \n  console.log(`Page title: ${await page.title()}`);\n  \n  // Clean up\n  await browser.disconnect();\n  console.log(\"Disconnected from browser.\");\n})();\n","lang":"javascript"},"children":[]}]},"headings":[{"value":"Node.js Puppeteer オートメーション","id":"nodejs-puppeteer-オートメーション","depth":1},{"value":"前提条件","id":"前提条件","depth":2},{"value":"スクリプト例","id":"スクリプト例","depth":2}],"frontmatter":{"seo":{"title":"Node.js Puppeteer オートメーション"}},"lastModified":"2026-06-10T11:47:34.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/api-reference/examples/puppeteer","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}