---
title: Serverless Functions - Javascript on real browsers
description: Run Serverless Javascript on real browsers in the TestingBot browser
  grid.
source_url:
  html: https://testingbot.com/support/functions/serverless
  md: https://testingbot.com/support/functions/serverless/index.md
---
# /function

This function endpoint allows you to `POST` Javascript code.   
 TestingBot will run the Javascript code on the browser you specified and return the response generated from the code.

## Basic Example

In the example below, we'll pass code that directly interfaces with Puppeteer.

    curl -X POST https://cloud.testingbot.com/scrape?key=YOUR_KEY&secret=YOUR_SECRET \
    -H 'Content-Type: application/json' \
    -d '{
      "code": "module.exports=async({page:a,context:b})=>{const{url:c}=b;await a.goto(c);const d=await a.content();return{data:d,type:\\\"application/html\\\"}};",
      "context": {
        "url": "https://testingbot.com/"
      }
    }'

We use the `page` object, which is a [Puppeteer Page Object](https://pptr.dev/api/puppeteer.page) and `context` which you can compare with function arguments that we pass in as an object.

The example above will open a new browser session and execute the code in the `code` with `context` as arguments. Once the function has completed, you will receive the response.

## Advanced Example

You can run other Javascript code in the serverless function as well, for example let's say you want to calculate something. Of course this is a trivial example, but it shows the capabilities of running arbitrary Javascript code in the cloud.

    curl -X POST https://cloud.testingbot.com/scrape?key=YOUR_KEY&secret=YOUR_SECRET \
    -H 'Content-Type: application/json' \
    -d '{
      "code": "module.exports=async()=>{const d = 4+4; return{data:d,type:\"application/html\"}};",
      "context": {}
    }'

This will run a function that simply does a `4 + 4` calculation and return the result.

Was this page helpful? Yes No 

## Looking for More Help?

Have questions or need more information?   
 You can reach us via the following channels:

- [Email us](https://testingbot.com/contact/new)
- [Join our Slack Channel](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
