Developers: Code a Phantom

Follow this guide to code your own Phantom, or check out the Developer Hub!

 

First, here are some relevant definitions to keep in mind:

Script:

The code that will be executed by node.js in the cloud, using Puppeteers, PhantomBuster libraries, and more. 

Catalog:

The list of scripts you can execute in our cloud. For example, PhantomBuster provides a public catalog of scripts.

Phantom:

A Phantom is a Headless Chrome that runs a script in the cloud.

Workspace:

When you sign up for an account on PhantomBuster, a Workspace is automatically created for you. It represents the Phantoms you'll use and the scripts you'll code. Your Workspace contains your catalog of Phantoms that you can share or not. e.g., PhantomBuster's catalog is public.

Branch:

Your catalog displays the "master" branch. You can create as many branches as you want. Each script can be shared and executed. Each branch is composed of 

  1. - Staging
  2. - Release 

Setup:

The multiple section setup for configuring a Phantom. Usually composed of two steps: 

  1. The input you'll need from the user, written in JSON
  2. The launch settings, such as the frequency, and notifications

 

Create and execute a Phantom

This article will guide you from the creation of a script to its public release into the catalog of your Workspace. Before you begin, make sure you've enabled developer mode on your account.

 

Create a script

From the 'My Phantoms' page, go to the 'Developer' section:

    • Menu (top right)
    • Developer

Set up a new script:

    • Create script
    • Set a name (no extension needed)
Screenshot_2022-06-22_at_16.25.37.png

Attach the script to the “master” branch 

    • Three little dots
    • Branch into...
    • Set branch name (“master”)
Screenshot_2022-06-22_at_16.26.40.png

Code a Phantom

    • Go to the Phantom's page
    • Three little dots
    • Make public
    • Again, three little dots
    • Edit code
    • Code (see sample code)
    • Save and close the editor
// Phantombuster configuration {
"phantombuster command: nodejs"
"phantombuster package: 5"
"phantombuster flags: save-folder"

const Buster = require("phantombuster")
const buster = new Buster()
const puppeteer = require('puppeteer')
// }

;(async () => {
const browser = await puppeteer.launch({
args: ["--no-sandbox"] // this is needed to run Puppeteer in a Phantombuster container
})
const page = await browser.newPage()
await page.goto('https://news.ycombinator.com')
await page.screenshot({path: 'screenshot.png'})
await buster.setResultObject({pageTitle: await page.title()})
await page.close()
await browser.close()
process.exit()
})()

 

Test Phantom in staging mode

    • Use this Phantom
    • Go through the Setup and save
    • Launch

Debug the code

    • Three little dots
    • Toggle console

Set the Phantom as public

    • Menu
    • Developer
    • Select the “master” branch
    • Select the script to publish
    • Release

Share your Phantom

    • Select the Release option
    • Share your script link
    • ...or the link of your catalog (only public scripts will be available)

SDK

If you don't want to use the built-in script editor, you can use our SDK. See this guide for more details.

 

Support

If you have any questions about the creation of scripts, please tell us using the support button!

 

If you think this article does not address your issue, please contact Support directly. We are continuously improving, so your feedback means the world to us!

Was this article helpful?
5 out of 13 found this helpful