Features

/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 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. Ofcourse 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.