Skip to content

Instantly share code, notes, and snippets.

@rocel
Forked from addyosmani/headless.md
Created April 12, 2017 20:14
Show Gist options
  • Select an option

  • Save rocel/45cd54f7dfb1056d1a90f9946566c198 to your computer and use it in GitHub Desktop.

Select an option

Save rocel/45cd54f7dfb1056d1a90f9946566c198 to your computer and use it in GitHub Desktop.

Revisions

  1. @addyosmani addyosmani revised this gist Apr 3, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion headless.md
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,13 @@

    If you're looking at this in 2016 and beyond, I strongly recommend investigating real headless Chrome: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md

    Windows and Mac users might find using Justin Ribeiro's [Docker setup](https://t.co/wyVjzUVmBe) useful here while full support for these platforms is being worked out.

    You can use `chrome --headless` on Linux as of M57 but note you'll need to build the binaries yourself for now.

    The metabug for adding headless mode to Chromium is [over here](https://bugs.chromium.org/p/chromium/issues/detail?id=546953).

    If you're on Ubuntu or working with a Linux VM...
    Otherwise, if you're on Ubuntu or working with a Linux VM that isn't working with Linux:

    ## Step 1: Install the Ubuntu dependencies needed:

  2. @addyosmani addyosmani revised this gist Apr 3, 2017. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions headless.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    # Update

    If you're looking at this in 2016, I strongly recommend investigating real headless Chrome: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
    If you're looking at this in 2016 and beyond, I strongly recommend investigating real headless Chrome: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md

    #If you're on Ubuntu or working with a Linux VM...
    The metabug for adding headless mode to Chromium is [over here](https://bugs.chromium.org/p/chromium/issues/detail?id=546953).

    If you're on Ubuntu or working with a Linux VM...

    ## Step 1: Install the Ubuntu dependencies needed:

    @@ -31,7 +33,7 @@ Start and open a page:
    xvfb-run --server-args='-screen 0, 1024x768x16' google-chrome -start-maximized http://www.example.com > /dev/null &
    ```

    #If you're on Windows..
    # If you're on Windows..

    Use [Desktops](http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx) from the MS SysInternals package. You can spawn your Chrome process directly from the "hidden" desktop and keep it working there (I have not personally tested this).

  3. @addyosmani addyosmani revised this gist Oct 6, 2016. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions headless.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    # Update

    If you're looking at this in 2016, I strongly recommend investigating real headless Chrome: https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md

    #If you're on Ubuntu or working with a Linux VM...

    ## Step 1: Install the Ubuntu dependencies needed:
  4. @addyosmani addyosmani revised this gist Apr 8, 2013. 2 changed files with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion headless.md
    Original file line number Diff line number Diff line change
    @@ -34,4 +34,4 @@ Use [Desktops](http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx) fr
    #Other options...

    You could try spawning Chrome as a child process using something like Node.js and piping the output back to the terminal.
    See chrome.js for an example of how to do this (todo: update to latest Express).
    See runChrome.js for an example of how to do this (todo: update to latest Express).
    File renamed without changes.
  5. @addyosmani addyosmani revised this gist Apr 8, 2013. 2 changed files with 51 additions and 0 deletions.
    50 changes: 50 additions & 0 deletions chrome.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    var express = require('express');
    var http = require('http');
    var cp = require('child_process');
    var port = 3000;
    var app = express();
    //var app = express();
    //var server = http.createServer(app);
    var chrome_count = 0;


    app.get('/', function(req, res){
    startChrome(chrome_count++,9222,function chromeStared(err,id,chrome){
    res.send('Chrome '+id+' Started\r\n');
    console.log('Simulating some data parsing');
    setTimeout(function(){
    console.log('Shutdown chrome '+id);
    chrome.kill('doh!');
    },1000);
    });
    });


    app.listen(port);
    console.log('Server is listening on port ' + port);

    function startChrome(id,port,callback){
    var terminal = cp.spawn('bash');
    var chrome = {};

    terminal.on('exit', function (code) {

    console.log('Starting chrome');
    chrome = cp.spawn('/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome',[
    '--remote-debugging-port='+port,
    '--user-data-dir=/Volumes/DATA/repos/scrapper/userdata',
    'http://www.chrome.com'
    ]);
    callback(null,id,chrome);
    });

    setTimeout(function() {
    console.log('Sending stdin to terminal');
    //terminal.stdin.write('echo "Hello $USER"');
    terminal.stdin.write('rm -rf /Volumes/DATA/repos/scrapper/userdata'+'\n');
    terminal.stdin.write('mkdir /Volumes/DATA/repos/scrapper/userdata'+'\n');
    terminal.stdin.write('touch "/Volumes/DATA/repos/scrapper/userdata/First Run"'+'\n');
    terminal.stdin.write('chmod 777 "/Volumes/DATA/repos/scrapper/userdata/First Run"'+'\n');
    terminal.stdin.end();
    }, 5000);
    }
    1 change: 1 addition & 0 deletions headless.md
    Original file line number Diff line number Diff line change
    @@ -34,3 +34,4 @@ Use [Desktops](http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx) fr
    #Other options...

    You could try spawning Chrome as a child process using something like Node.js and piping the output back to the terminal.
    See chrome.js for an example of how to do this (todo: update to latest Express).
  6. @addyosmani addyosmani revised this gist Apr 8, 2013. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions headless.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    If you're on Ubuntu or working with a Linux VM...
    #If you're on Ubuntu or working with a Linux VM...

    ## Step 1: Install the Ubuntu dependencies needed:

    @@ -27,6 +27,10 @@ Start and open a page:
    xvfb-run --server-args='-screen 0, 1024x768x16' google-chrome -start-maximized http://www.example.com > /dev/null &
    ```

    If you're on Windows..
    #If you're on Windows..

    Use [Desktops](http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx) from the MS SysInternals package. You can spawn your Chrome process directly from the "hidden" desktop and keep it working there (I have not personally tested this).
    Use [Desktops](http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx) from the MS SysInternals package. You can spawn your Chrome process directly from the "hidden" desktop and keep it working there (I have not personally tested this).

    #Other options...

    You could try spawning Chrome as a child process using something like Node.js and piping the output back to the terminal.
  7. @addyosmani addyosmani revised this gist Apr 8, 2013. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion headless.md
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,8 @@ Start and open a page:

    ```
    xvfb-run --server-args='-screen 0, 1024x768x16' google-chrome -start-maximized http://www.example.com > /dev/null &
    ```
    ```

    If you're on Windows..

    Use [Desktops](http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx) from the MS SysInternals package. You can spawn your Chrome process directly from the "hidden" desktop and keep it working there (I have not personally tested this).
  8. @addyosmani addyosmani revised this gist Apr 8, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions headless.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    If you're on Ubuntu or working with a Linux VM...

    ## Step 1: Install the Ubuntu dependencies needed:

    SSH into your server as a root or do sudo -i.
  9. @addyosmani addyosmani revised this gist Apr 8, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions headless.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    1. Install the Ubuntu dependencies needed:
    ## Step 1: Install the Ubuntu dependencies needed:

    SSH into your server as a root or do sudo -i.

    @@ -11,7 +11,7 @@ apt-get install -y python-gobject-2
    apt-get install -y curl git
    ```

    2. Options for starting:
    ## Step 2. Options for starting:

    Normal:

  10. @addyosmani addyosmani created this gist Apr 8, 2013.
    26 changes: 26 additions & 0 deletions headless.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    1. Install the Ubuntu dependencies needed:

    SSH into your server as a root or do sudo -i.

    Then install necessary software:

    ```
    apt-get update
    apt-get install -y xvfb fluxbox x11vnc dbus libasound2 libqt4-dbus libqt4-network libqtcore4 libqtgui4 libxss1 libpython2.7 libqt4-xml libaudio2 libmng1 fontconfig liblcms1 lib32stdc++6 lib32asound2 ia32-libs libc6-i386 lib32gcc1 nano
    apt-get install -y python-gobject-2
    apt-get install -y curl git
    ```

    2. Options for starting:

    Normal:

    ```
    xvfb-run --server-args='-screen 0, 1024x768x16' google-chrome -start-maximized > /dev/null &
    ```

    Start and open a page:

    ```
    xvfb-run --server-args='-screen 0, 1024x768x16' google-chrome -start-maximized http://www.example.com > /dev/null &
    ```