mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(Launcher): fix dumpio bug (#2071)
This patch fixes `dumpio` launcher option. Fixes #2046
This commit is contained in:
parent
ee7ebd6e17
commit
66887743ea
@ -100,10 +100,9 @@ class Launcher {
|
|||||||
if (Array.isArray(options.args))
|
if (Array.isArray(options.args))
|
||||||
chromeArguments.push(...options.args);
|
chromeArguments.push(...options.args);
|
||||||
|
|
||||||
const stdio = options.dumpio ? ['inherit', 'inherit', 'inherit'] : ['pipe', 'pipe', 'pipe'];
|
const stdio = ['pipe', 'pipe', 'pipe'];
|
||||||
if (options.appMode)
|
if (options.appMode)
|
||||||
stdio.push('pipe', 'pipe');
|
stdio.push('pipe', 'pipe');
|
||||||
|
|
||||||
const chromeProcess = childProcess.spawn(
|
const chromeProcess = childProcess.spawn(
|
||||||
chromeExecutable,
|
chromeExecutable,
|
||||||
chromeArguments,
|
chromeArguments,
|
||||||
@ -114,6 +113,11 @@ class Launcher {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (options.dumpio) {
|
||||||
|
chromeProcess.stderr.pipe(process.stderr);
|
||||||
|
chromeProcess.stdout.pipe(process.stdout);
|
||||||
|
}
|
||||||
|
|
||||||
let chromeClosed = false;
|
let chromeClosed = false;
|
||||||
const waitForChromeToClose = new Promise((fulfill, reject) => {
|
const waitForChromeToClose = new Promise((fulfill, reject) => {
|
||||||
chromeProcess.once('close', () => {
|
chromeProcess.once('close', () => {
|
||||||
|
9
test/fixtures/dumpio.js
vendored
Normal file
9
test/fixtures/dumpio.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
(async() => {
|
||||||
|
const [, , puppeteerRoot, options, emptyPage, dumpioTextToLog] = process.argv;
|
||||||
|
const browser = await require(puppeteerRoot).launch(JSON.parse(options));
|
||||||
|
const page = await browser.newPage();
|
||||||
|
await page.goto(emptyPage);
|
||||||
|
await page.evaluate(_dumpioTextToLog => console.log(_dumpioTextToLog), dumpioTextToLog);
|
||||||
|
await page.close();
|
||||||
|
await browser.close();
|
||||||
|
})();
|
12
test/test.js
12
test/test.js
@ -271,6 +271,18 @@ describe('Puppeteer', function() {
|
|||||||
const args = puppeteer.defaultArgs();
|
const args = puppeteer.defaultArgs();
|
||||||
expect(args).toContain('--no-first-run');
|
expect(args).toContain('--no-first-run');
|
||||||
});
|
});
|
||||||
|
it('should dump browser process stderr', async({server}) => {
|
||||||
|
const dumpioTextToLog = 'MAGIC_DUMPIO_TEST';
|
||||||
|
let dumpioData = '';
|
||||||
|
const {spawn} = require('child_process');
|
||||||
|
const options = Object.assign({dumpio: true}, defaultBrowserOptions);
|
||||||
|
const res = spawn('node',
|
||||||
|
[path.join(__dirname, 'fixtures', 'dumpio.js'), PROJECT_ROOT, JSON.stringify(options), server.EMPTY_PAGE, dumpioTextToLog]);
|
||||||
|
res.stderr.on('data', data => dumpioData += data.toString('utf8'));
|
||||||
|
await new Promise(resolve => res.on('close', resolve));
|
||||||
|
|
||||||
|
expect(dumpioData).toContain(dumpioTextToLog);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('Puppeteer.connect', function() {
|
describe('Puppeteer.connect', function() {
|
||||||
it('should be able to connect multiple times to the same browser', async({server}) => {
|
it('should be able to connect multiple times to the same browser', async({server}) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user