{"library":"screenshotone-api-sdk","title":"ScreenshotOne API JavaScript SDK","description":"The `screenshotone-api-sdk` is the official client library for the ScreenshotOne.com API, enabling developers to programmatically generate and download screenshots of any website. It provides a fluent API for configuring various screenshot options, such as delay, ad blocking, and more, directly mirroring the latest API specifications. The current stable version is 1.1.21. The package appears to have an active release cadence, with continuous integration indicated by its build badge and consistent updates to synchronize with the underlying ScreenshotOne API. Key differentiators include its tight integration with the ScreenshotOne service, offering specific error handling for API-level issues, and providing both URL generation and direct screenshot download functionalities. It is designed for both JavaScript and TypeScript environments, shipping with its own type definitions.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install screenshotone-api-sdk"],"cli":null},"imports":["import { Client } from 'screenshotone-api-sdk';","import { TakeOptions } from 'screenshotone-api-sdk';","import { APIError } from 'screenshotone-api-sdk';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as fs from 'fs';\nimport { Client, TakeOptions, APIError } from 'screenshotone-api-sdk';\n\n// Create API client using environment variables for security\nconst accessKey = process.env.SCREENSHOTONE_ACCESS_KEY ?? '';\nconst secretKey = process.env.SCREENSHOTONE_SECRET_KEY ?? '';\n\nif (!accessKey || !secretKey) {\n  console.error('SCREENSHOTONE_ACCESS_KEY and SCREENSHOTONE_SECRET_KEY environment variables must be set.');\n  process.exit(1);\n}\n\nconst client = new Client(accessKey, secretKey);\n\nasync function generateAndDownloadScreenshot() {\n  // Set up options for the screenshot\n  const options = TakeOptions\n      .url(\"https://www.example.com\")\n      .delay(2) // Wait 2 seconds before taking the screenshot\n      .blockAds(true)\n      .fullPage(true) // Capture the entire page\n      .viewportWidth(1280) // Set viewport width\n      .viewportHeight(800); // Set viewport height\n\n  try {\n      // Generate a signed URL for the screenshot\n      const url = client.generateTakeURL(options);\n      console.log('Generated screenshot URL:', url);\n\n      // Download the screenshot directly\n      console.log('Downloading screenshot...');\n      const imageBlob = await client.take(options);\n\n      const buffer = Buffer.from(await imageBlob.arrayBuffer());\n      const outputPath = 'example-screenshot.png';\n      fs.writeFileSync(outputPath, buffer);\n      console.log(`Screenshot saved to ${outputPath}`);\n  } catch (error) {\n      if (error instanceof APIError) {\n          console.error(`ScreenshotOne API Error: ${error.errorMessage} (Status: ${error.httpStatusCode}, Code: ${error.errorCode})`);\n          console.error(`Documentation: ${error.documentationUrl}`);\n      } else if (error instanceof Error) {\n          console.error(\"An unexpected error occurred:\", error.message);\n      } else {\n          console.error(\"An unknown error occurred:\", error);\n      }\n  }\n}\n\ngenerateAndDownloadScreenshot();","lang":"typescript","description":"This quickstart demonstrates how to initialize the ScreenshotOne client, configure screenshot options using the fluent API, generate a signed URL, and then download the resulting screenshot to a local file. It also includes error handling for both API-specific and generic errors.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}