• Builds
  • latest 0.0.2 / 2018-09-09
  • Created 2018-04-11
  • Last modified 2018-09-12
  • grade 2


Example act that opens a webpage with Golden Gate webcam stream. It takes a screenshot from the stream and saves it as output to key-value store. You can easily use it as API that returns a screenshot with:[YOUR_API_TOKEN]


To run the actor, send a HTTP POST request to:<YOUR_API_TOKEN>

The POST payload will be passed as input for the actor. For more information, read the docs.

Example input

Content type: application/json; charset=utf-8

{ "hello": 123 }

Source code

Based on the apify/actor-node-chrome Docker image (see docs).

const Apify = require('apify');

Apify.main(async () => {
    // Start browser.
    const browser = await Apify.launchPuppeteer({ headless: true });

    // Load and get an iframe
    // containing webcam stream.
    console.log('Opening page.');
    const page = await browser.newPage();
    await page.goto('');
    const iframe = (await page.frames()).pop();

    // Get webcam image element handle.
    const imageElementHandle = await iframe.$('.VideoColm img');

    // Give the webcam image some time to load.
    console.log('Waiting for some time...');
    await Apify.utils.sleep(3000);

    // Get a screenshot of that image.
    const imageBuffer = await imageElementHandle.screenshot();
    console.log('Screenshot captured.');

    // Save it as an OUTPUT. Just as INPUT, OUTPUT has a special meaning.
    // Anything you save as an OUTPUT to KeyValueStore will be sent to you
    // as an API response once the actor finishes its run, if you use the
    // run-sync API. This way, you can really Apify any website.
    await Apify.setValue('OUTPUT', imageBuffer, { contentType: 'image/jpeg' });
    console.log('Actor finished.');