Browserless functions and usage-based accounts!

Joel Griffith
Joel Griffith
/
May 26, 2018
Usage-based accounts are now live! Read more about them here.

We're extremely excited to announce that we'll soon be entering a closed-beta for browserless functions and a new payment option: usage-based payment! We've listened to your comments and suggestions, and we hope these new features will give you flexibility on how to organize your headless-browser work and how to pay for it!

New usage-based accounts

The first upcoming feature we're excited to announce is usage-based, or pay for what you use style accounts. If you don't regularly run headless work, or just need to run it on occasion, then this plan is a perfect fit for you.

With pay-per-use you only pay for the time your headless script is running. At the time of this writing we're aiming for a cost of $0.00008 a second. Below is a table of common scenarios and how much it costs to run them.

New usage-based accounts

Type of sessionTotal TimeCostCapture a full-site screenshot with /screenshot2 seconds running$0.00016Generate a 5-page PDF with /pdf5 seconds running$0.0004Scrape 100 pages in parallel30 seconds running (each)$0.24Run a unit-test with 50 specs in parallel5 seconds (each)$0.02Complex sign-up test of your web-app25 minutes$0.12Complex interaction with 20 pages in parallel25 minutes (each)$2.40

Usage-based accounts will utilize credits for paying, meaning you can put down as little as $5.00 to start running headless work. When your balance runs low, we'll either let you know via email or charge you automatically if you'd like. This will prevent one of the worst feelings that we've experienced on other cloud providers: overspending.

If you're interested in trying out usage-based accounts, please send us an email with your use-case and we'll let you know if you're a good fit for the closed alpha.

browserless functions

If you've been watching the github repo for browserless, you may have noticed some pull-requests and features have recently been merged. The first is the notion of "functions" which are an easy way to execute headless work without being restricted to having a NodeJS backend. For common use-cases (like pdf's or screenshots), we've added some top-level routes to now help you achieve your goals.

Take a screenshot


// POST to https://chrome.browserless.io/screenshot
{
  "url": "https://example.com",
  // See https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#pagescreenshotoptions for more details
  "options": {
    "type": "jpeg",
    "quality": 10
  }
}

Get a PDF


// POST to https://chrome.browserless.io/pdf
{
  "url": "https://example.com",
  // See https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#pagepdfoptions for more details
  "options": {
    "printBackground": false
  }
}

Get page content


// POST to https://chrome.browserless.io/content
{
  "url": "https://example.com"
}

If you're interested in the details of how these run, feel free to see the code located here. You can also pull the browserless image on docker and check it out!

Authoring your own functions

If you need more flexibility in what you're trying to achieve, you can actually author your own functions and have browserless execute them for you via a simple HTTP POST request.

These functions accept a JSON body with two fields: code and contextcode is string of the NodeJS code you want to run (running on Node 8 LTS), and context is anything you wish to pass your code.

Let's say you want to go a page and click the first anchor then capture the screenshot. Your code would look something like this:

browserless function


module.exports = async ({ page, context }) => {
  const { url, click } = context;
  await page.goto(url);
  page.click(click);

  await page.waitForNavigation();

  const data = await page.screenshot();

  // Return two properties:
  // 'data' => Buffer, string, or JSON data
  // 'type' => A string indicating what content-type `data` is (png here)
  return {
    data,
    type: 'png',
  };
};

You'll notice that we are passing in references to via a context object. This allows you to specify runtime arguments without having to change your code, thus making it more static. Once we have this inplace, we can call it via the /function endpoint:

Executing your function


// POST to https://chrome.browserless.io/function
// Code has been minified via https://babeljs.io/repl
{
  "code": "module.exports=async({page:a,context:b})=>{const{url:c,click:d}=b;await a.goto(c),a.click(d),await a.waitForNavigation();const e=await a.screenshot();return{data:e,type:'png'}};",
  "context": {
    "url": "https://example.com/",
    "click": "a"
  }
}

We'll soon have a full set of authoring tools for browserless functions as part of our paid plans, allowing you to create hosted functions with a simple URL to use in order to call them.

Talk with us

Starting today you can utilize browserless functions on any paid plans. Simply update the version of Chrome in the account screen and you're ready to go!

If you're interested in applying for the closed-alpha, please send us an email at alpha@browserless.io and we'll get back to you shortly. If you have any questions, feel free to ask us as well.

Share this article

Ready to try the benefits of Browserless?

Sign Up