Code Monkey home page Code Monkey logo

envato's Introduction

About

This is a Debian based Docker container that contains Chrome (NOT Chromium) and Node.js to run Puppeteer scripts/tests.

Why does this exist?

There are several projects that open a URL in a headless browser, but this project aims to provide a little extra whilst maintaining it's simplicity.

  • It uses Chrome, not Chromium - some more complex features are not available in Chromium headless mode, such as WebRTC.
  • This combines Puppeteer, so you can pass a script and write tests not just open a URL.

Install Guide

(async() => {

    const browser = await puppeteer.launch({
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox'
        ],
        headless: true,
        executablePath: '/usr/bin/google-chrome'
    });

    const page = await browser.newPage();

    await page.goto('https://google.com', {waitUntil: 'networkidle2'});

    await page.screenshot({path: '/app/screenshots/screen.png', fullPage: true})

    // Get the "viewport" of the page, as reported by the page.
    const dimensions = await page.evaluate(() => {
        return {
            width: document.documentElement.clientWidth,
            height: document.documentElement.clientHeight,
            deviceScaleFactor: window.devicePixelRatio
        };
    });

    console.log('Dimensions:', dimensions);
    browser.close();

})();
  • Build the container

docker build -t my-webtest .

  • Run the docker container

docker run --rm --name webtest -v $(pwd)/webtest.js:/app/src/index.js my-webtest

Taking screenshots

Note: in your webtest.js you must output screenshots to the correct output dir: "/app/screenshots/"

docker run --rm --name webtest -v $(pwd)/screenshots:/app/screenshots -v $(pwd)/webtest.js:/app/src/index.js my-webtest

Faking a video stream

Use these args below to pass to Chrome. Note:

  • video file path should be absolute
  • mount your video file into the container /app/src -v $(pwd)/src/video.y4m:/app/src/video.y4m
  • some WebRTC streams check for a minimum video resolution, for best results use a high res video like 720p or above

const browser = await puppeteer.launch({
    args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--use-fake-ui-for-media-stream=1',
        '--use-fake-device-for-media-stream=1',
        '--use-file-for-fake-video-capture=/home/user/Documents/folder/src/video.y4m',
        '--allow-file-access=1'
    ],
    headless: true,
    executablePath: '/usr/bin/google-chrome'
});

envato's People

Contributors

devrutherles avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.