Skip to content

Latest commit

 

History

History
519 lines (333 loc) · 10.2 KB

api.md

File metadata and controls

519 lines (333 loc) · 10.2 KB

API Documentation

Chromeless provides TypeScrip typings.

Chromeless methods

Chrome methods


End the Chromeless session. Locally this will disconnect from Chrome. Over the Proxy, this will end the session, terminating the Lambda function. It returns the last value that has been evaluated.

await chromeless.end()

Navigate to a URL.

Arguments

  • url - URL to navigate to

Example

await chromeless.goto('https://google.com/')

Click on something in the DOM.

Arguments

  • selector - DOM selector for element to click

Example

await chromeless.click('#button')

Wait for some duration. Useful for waiting for things download.

Arguments

  • timeout - How long to wait, in ms

Example

await chromeless.wait(1000)

Wait until something appears. Useful for waiting for things to render.

Arguments

  • selector - DOM selector to wait for

Example

await chromeless.wait('div#loaded')

Wait until a function returns.

Arguments

  • fn - Function to wait for
  • [arguments] - Arguments to pass to the function

Example

await chromeless.wait(() => { return console.log('@TODO: put a better example here') })

Provide focus on a DOM element.

Arguments

  • selector - DOM selector to focus

Example

await chromeless.focus('input#searchField')

Send a key press. Enter, for example.

Arguments

  • keyCode - Key code to send
  • count - How many times to send the key press
  • modifiers - Modifiers to send along with the press (e.g. control, command, or alt)

Example

await chromeless.press(13)

Type something (into a field, for example).

Arguments

  • input - String to type
  • selector - DOM element to type into

Example

const result = await chromeless
  .goto('https://www.google.com')
  .type('chromeless', 'input[name="q"]')

Not implemented yet


Not implemented yet


Not implemented yet


Not implemented yet


Not implemented yet


Scroll to somewhere in the document.

Arguments

  • x - Offset from top of the document
  • y - Offset from the left of the document

Example

await chromeless.scrollTo(500, 0)

Resize the viewport. Useful if you want to capture more or less of the document in a screenshot.

Arguments

  • width - Viewport width
  • height - Viewport height

Example

await chromeless.viewport(1024, 800)

Evaluate Javascript code within Chrome in the context of the DOM.

Arguments

  • fn - Function to evaluate within Chrome
  • [arguments] - Arguments to pass to the function

Example

await chromeless.evaluate(() => {
    // this will be executed in Chrome
    const links = [].map.call(
      document.querySelectorAll('.g h3 a'),
      a => ({title: a.innerText, href: a.href})
    )
    return JSON.stringify(links)
  })

Get the value of an input field.

Arguments

  • selector - DOM input element

Example

await chromeless.inputValue('input#searchField')

Test if a DOM element exists in the document.

Arguments

  • selector - DOM element to check for

Example

await chromeless.exists('div#ready')

Take a screenshot of the document as framed by the viewport. When running Chromeless locally this returns the local file path to the screenshot image. When run over the Chromeless Proxy service, a URL to the screenshot on S3 is returned.

Example

const screenshot = await chromeless
  .goto('https://google.com/')
  .screenshot()

console.log(screenshot) // prints local file path or S3 URL

Not implemented yet


Returns all browser cookies for the current URL.

Example

await chromeless.cookiesGet()

Returns a specific browser cookie by name for the current URL.

Arguments

  • name - Name of the cookie to get

Example

const cookie = await chromeless.cookiesGet('creepyTrackingCookie')

Not implemented yet


Returns all browser cookies. Nam nom nom.

Example

await chromeless.cookiesGetAll()

Sets a cookie with the given name and value.

Arguments

  • name - Name of the cookie
  • value - Value of the cookie

Example

await chromeless.cookiesSet('visited', '1')

Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist.

Arguments

  • cookie - The cookie data to set

Example

await chromeless.cookiesSet({
  url: 'http://google.com/',
  domain: 'google.com',
  name: 'userData',
  value: '{}',
  path: '/',
  expires: 0,
  size: 0,
  httpOnly: false,
  secure: true,
  session: true,
})

Sets many cookies with the given cookie data; may overwrite equivalent cookies if they exist.

Arguments

  • url - URL to navigate to

Example

await chromeless.cookiesSet([
  {
    url: 'http://google.com/',
    domain: 'google.com',
    name: 'userData',
    value: '{}',
    path: '/',
    expires: 0,
    size: 0,
    httpOnly: false,
    secure: true,
    session: true,
  }, {
    url: 'http://bing.com/',
    domain: 'bing.com',
    name: 'userData',
    value: '{}',
    path: '/',
    expires: 0,
    size: 0,
    httpOnly: false,
    secure: true,
    session: true,
  }
])

Not implemented yet


Clears browser cookies.

Example

await chromeless.cookiesClearAll()