Skip to main content

Constructor

Create a new Opensteer instance with optional configuration.
import { Opensteer } from 'opensteer'

const opensteer = new Opensteer(config?: OpensteerConfig)

Configuration options

name
string
Namespace for selector persistence. Selectors are stored in .opensteer/selectors/<name>/. Defaults to a hash of the current working directory.
browser
OpensteerBrowserConfig
Browser launch configuration.
storage
OpensteerStorageConfig
Storage configuration for selector persistence.
cloud
boolean | OpensteerCloudOptions
Enable cloud mode. Can be true for defaults or an options object. See cloud configuration for details.
model
string
Default AI model for element resolution and extraction. Format: "provider/model". Example: "openai/gpt-4o"
debug
boolean
Enable debug logging. Default: false

Static methods

Opensteer.from()

Wrap an existing Playwright Page without launching a new browser. The caller retains ownership of the browser lifecycle.
import { chromium } from 'playwright'
import { Opensteer } from 'opensteer'

const browser = await chromium.launch()
const page = await browser.newPage()
const opensteer = Opensteer.from(page, { name: 'my-scraper' })

// Use opensteer methods
await opensteer.goto('https://example.com')

// Caller is responsible for closing
await browser.close()
page
Page
required
Playwright Page instance to wrap.
config
OpensteerConfig
Optional configuration. Same as constructor config.
This method is not supported in cloud mode. It only works with local browser instances.

Properties

page

Access the underlying Playwright Page instance.
const title = await opensteer.page.title()
await opensteer.page.keyboard.press('Escape')
Throws if accessed before launch() or Opensteer.from().

context

Access the underlying Playwright BrowserContext instance.
const cookies = await opensteer.context.cookies()
await opensteer.context.clearCookies()
Throws if accessed before launch() or Opensteer.from().

Examples

Basic configuration

const opensteer = new Opensteer({
  name: 'my-scraper',
  browser: {
    headless: true
  }
})

await opensteer.launch()
await opensteer.goto('https://example.com')
await opensteer.close()

Cloud mode

const opensteer = new Opensteer({
  name: 'my-scraper',
  cloud: {
    apiKey: process.env.OPENSTEER_API_KEY
  }
})

await opensteer.launch()
const sessionUrl = opensteer.getCloudSessionUrl()
console.log('View session:', sessionUrl)
await opensteer.close()

Custom browser profile

const opensteer = new Opensteer({
  name: 'authenticated-scraper',
  browser: {
    profileDir: './browser-profile',
    headless: false
  }
})

await opensteer.launch()
// Cookies and session data persisted in ./browser-profile

With AI model configuration

const opensteer = new Opensteer({
  name: 'ai-scraper',
  model: 'anthropic/claude-3-5-sonnet-20241022'
})

await opensteer.launch()
await opensteer.goto('https://example.com')

// AI will use configured model for element resolution
await opensteer.click({ description: 'main call to action button' })