Actor picture

Example Golden Gate Webcam

apify/example-golden-gate-webcam

Example actor that opens a webpage with Golden Gate webcam. It takes a screenshot from the cam and saves it as output to the 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]

No credit card required

Author's avatarApify Technologies
  • Modified
  • Users17
  • Runs52
Actor picture

Example Golden Gate Webcam

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

const Apify = require('apify');

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

    // Load http://goldengatebridge75.org/news/webcam.html and get an IFRAME with the webcam stream
    console.log('Opening web page...');
    const page = await browser.newPage();
    await page.goto('http://goldengatebridge75.org/news/webcam.html');
    const frames = await page.frames();
    const iframeWithVideo = frames[1];

    // Wait for the webcam to load.
    console.log('Waiting for the webcam image.');
    const imageElementHandle = await iframeWithVideo.waitForSelector('.VideoColm img[src^="blob:"]');
    // Wait a little more to give the browser a chance to display the image.
    await page.waitFor(1000);

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

    // Save the screenshot as the actor's output. By convention, similarly to "INPUT",
    // the actor's output is stored in the default key-value store under the "OUTPUT" key.
    await Apify.setValue('OUTPUT', imageBuffer, { contentType: 'image/jpeg' });
    console.log('Actor finished.');
});