andyearnshaw / docketeer

A tiny application that lets you use a dockerised browser for Puppeteer
The Unlicense
3 stars 1 forks source link

Support for --remote-debugging-pipe #5

Open andyearnshaw opened 2 years ago

andyearnshaw commented 2 years ago

This currently doesn't work and I'm too unfamiliar with pipes and file descriptors to fix it right now. This is how Puppeteer sets up the browser process's stdio when pipe: true is passed in the options:

    if (pipe) {
      if (dumpio) stdio = ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'];
      else stdio = ['ignore', 'ignore', 'ignore', 'pipe', 'pipe'];
    }

docker run only supports attaching (--attach, -a) to stdin, stdout and stderr so I'm not sure how this might be solved.

When Puppeteer runs with this option, the following output is repeatedly logged by Chrome:

[0517/102611.507508:ERROR:devtools_pipe_handler.cc(150)] Could not write into pipe
frank-dspeed commented 2 years ago

Final Solution!

import

import Puppeteer from 'puppeteer';

in case of firefox inside docker set product before running the next part:

Puppeteer._productName = 'firefox'

finaly launch

Puppeteer.launch({
    ignoreDefaultArgs: true, // use only our supplyed args: []
    executablePath: '/usr/bin/docker', // we want to run docker right?
    args: [
       // docker arguments
        'run', 
        '-p=9333:9333', 
        '-p=3000:3000',
        '-it',
        `${dockerImage}`,
        `/usr/bin/google-chrome`,
        // end docker arguments
        ...Puppeteer._launcher.defaultArgs({ 
                devtools: false, // devtools auto open needs headless false
                headless: true, // needs to be false if devtools auto open
                userDataDir // needs to get set here no where else is optional
         }),
         // Here comes what you would put into args in general
    ],
    pipe: true
}
frank-dspeed commented 2 years ago

maybe usefull https://github.com/docker/cli/issues/3198