Class: Command

Command


<protected> new Command(parent)

An Osmosis command.
Parameters:
Name Type Description
parent object parent instance
Returns:
Command

Members


document

Change context to the current Document.
Properties:
Name Type Description
document
See:
  • Command.doc

window

Change context to the current Window.
Properties:
Name Type Description
window

Methods


click(selector)

Click an HTML element and continue after all events finish.
Parameters:
Name Type Description
selector Selector Node(s) to click
Example
.click('#nav > a')
.then(function(window) {
     var ajax = window.document.querySelector("#ajaxContent");

     if (ajax.textContent.length > 0) {
         this.log("ajax loaded");
     }
})

config(option, value)

Set configuration options for the **preceeding** command on down the chain.
Parameters:
Name Type Argument Description
option string | object A `key` string or { key: value } object
value string <optional>
A value for the given `key`
See:
  • Osmosis.options
  • Osmosis.config

Set a cookie. Short for `.config({ cookies: ... })`. Note: Setting a cookie to `null` will delete the cookie.
Parameters:
Name Type Description
name string Cookie name
value string Cookie value
See:
  • Osmosis.config
  • Command.config

data(callback)

Calls a callback with the current {@data} object. Note: Don't use this command to modify the {@data} object. Please use Command.then instead.
Parameters:
Name Type Description
callback function A callback with an argument for {@data}

delay(delay)

Delay each context before continuing down the chain.
Parameters:
Name Type Description
delay number A number of milliseconds or a float of seconds.

do(function)

Execute each argument asynchronously using the current context and data. After each argument has finished, Command.do will continue to the immediately following command using the original context.
Parameters:
Name Type Argument Description
function Osmosis | middlewareCallback <repeatable>
Callbacks or instances

done(function)

Call a callback when the Osmosis instance has completely finished.
Parameters:
Name Type Description
function function Callback function

fail(selector)

Continue if the given selector does NOT match any nodes. If a node is found, a Command.error message well be sent.
Parameters:
Name Type Description
selector Selector A selector to match.
See:
  • Command.login
  • Command.filter

filter(match)

Check that the context node matches the given selector.
Parameters:
Name Type Description
match Selector A Selector to match

find(selector)

Search for nodes in the current Document.
Parameters:
Name Type Description
selector Selector | contextCallback | Command.learn
See:
  • Command.select

follow(selector)

Follow a url.
Parameters:
Name Type Description
selector Selector A selector string for link nodes

follow(match)

Continue if the context node contains the given string.
Parameters:
Name Type Description
match string | RegExp A string to match.

get(url, params)

Make an HTTP GET request.
Parameters:
Name Type Argument Description
url string | contextCallback An absolute or relative URL or a contextCallback that calls a URL.
params object <optional>
HTTP GET query parameters
See:
  • Command.post

Set an HTTP header. Short for `.config({ headers: ... })`
Parameters:
Name Type Description
name string Header name
value string Header value
See:
  • Osmosis.headers
  • Osmosis.config

headers(headers)

Set multiple HTTP headers. Short for `.config({ headers: ... })`.
Parameters:
Name Type Description
headers object { headerName: headerValue, ... }
See:
  • Osmosis.header
  • Osmosis.config

learn(name)

Osmosis learns to find dynamic content via static selectors.
Parameters:
Name Type Description
name string The name of the runtime variable
See:
  • Command.use

login(username, password)

Log in using a web page's login form.
Parameters:
Name Type Description
username string Username or email address
password string Password
See:
  • Command.success
  • Command.fail

match(match)

Continue if the context node innerText matches a RegExp.
Parameters:
Name Type Description
match string | RegExp A RegExp to match.

paginate(selector, limit)

Loads multiple pages. The first argument can alternatively be an object representing HTTP GET/POST parameters to modify. If the first argument is an object, numeric values will increment the existing parameter value by that amount. String values are treated as selectors and each corresponding parameter's value will be replaced with the content of the selected node.
Parameters:
Name Type Argument Description
selector selector A link or form to the next page.
limit number | Selector | middlewareCallback <optional>
Total number of pages to load.

parse(data, options)

Parse HTML or XML data
Parameters:
Name Type Description
data string | buffer XML/HTML data
options object Parse options
See:
  • Osmosis.parse

pause()

Pause an Osmosis instance.

post(url, data)

Make an HTTP POST request.
Parameters:
Name Type Argument Description
url string | contextCallback An absolute or relative URL or a contextCallback that calls a URL.
data object <optional>
HTTP POST data
See:
  • Command.get

proxy(proxy)

Set a proxy. Short for `.config({ proxy: ... })`
Parameters:
Name Type Description
proxy string | array A string or array of HTTP proxy URL(s)
See:
  • Osmosis.config

resume()

Resume an Osmosis instance.

select(selector)

Search for nodes in the current context.
Parameters:
Name Type Description
selector Selector | contextCallback | Command.learn A selector
See:
  • Command.find

set(data)

Set values in the data object. Note: Also accepts set(key, selector) as parameters
Parameters:
Name Type Description
data object Key/selector pairs to set.

stop()

Stop an Osmosis instance.

submit(selector, params)

Submit a form.
Parameters:
Name Type Description
selector Selector A selector for a
or submit button.
params object Keys/values for the form's inputs.

success(selector)

Continue if the given selector matches any nodes. If no nodes are found, a Command.error message will be sent.
Parameters:
Name Type Description
selector Selector A selector to match.
See:
  • Command.login
  • Command.filter

then(callback)

Execute a given callback.
Parameters:
Name Type Description
callback callback

train(object)

Teach Osmosis how to find content.
Parameters:
Name Type Description
object object { name: selector } pairs of training variables
See:
  • Command.learn

trigger(event, selector)

Trigger a DOM event and continue once it completes. Note: If no selector is specified, the default event target will be the Window object.
Parameters:
Name Type Argument Description
event string The name of the event to trigger.
selector Selector <optional>
Nodes to trigger the event on.

use()

Use a runtime defined variable
See:
  • Command.run
  • Command.learn

using(object)

Set variables to use.
Parameters:
Name Type Description
object object { key: value } pairs of variables
See:
  • Command.use