Act

apify/example-golden-gate-webcam

  • Builds
  • latest 0.0.1 / 2018-04-11
  • Created 2018-04-11
  • Last modified 2018-04-11
  • grade 2

Description

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: https://api.apify.com/v2/acts/apify~example-golden-gate-webcam/run-sync?token=[YOUR_API_TOKEN]


API

To run the act, send a HTTP POST request to:

https://api.apify.com/v2/acts/apify~example-golden-gate-webcam/runs?token=<YOUR_API_TOKEN>

The POST payload will be passed as input for the act. 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 () => {
    const browser = await Apify.launchPuppeteer();

    // Load http://goldengatebridge75.org/news/webcam.html and get an iframe
    // containing webcam stream.
    const page = await browser.newPage();
    await page.goto('http://goldengatebridge75.org/news/webcam.html');
    const iframe = (await page.frames()).pop();

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

    // Get a screenshot of that image.
    const imageBuffer = await imageElementHandle.screenshot();

    // Save it as an output.
    await Apify.setValue('OUTPUT', imageBuffer, { contentType: 'image/jpeg' });
});