Alejandro Vera
Alejandro Vera

Reputation: 377

launching chrome in playwright gets closed

I am trying to migrate from puppeteer to playwright. So I made a simple example program to experiment. This is my code.

import {Browser, chromium} from 'playwright-core'

class Factory {
    static async run() {
        const launchOptions = {
            defaultViewport: null,
            ignoreDefaultArgs: true,
            headless: true,
            executablePath: `/usr/bin/chromium-browser`,
        }
        console.log(`starting`)
        const browser: Browser =  await chromium.launch(launchOptions)
        console.log(`browser: ${browser}`)
        const context = await browser.newContext();
        console.log(`context: ${context}`)
        const page = await context.newPage();
        console.log(`page: ${page}`)
        await page.goto('https://example.com');
    }
}

Factory.run()

When I run this code chormium starts, but never goes beyond the starting log. Then, after a while, the browser stops and get this log:

starting
/home/alejo/git/node_test/index.ts:12
        const browser: Browser =  await chromium.launch(launchOptions)
                                                 ^
browserType.launch: Browser closed.
==================== Browser output: ====================
<launching> /usr/bin/chromium-browser 
<launched> pid=199346
=========================== logs ===========================
<launching> /usr/bin/chromium-browser 
<launched> pid=199346
============================================================
    at Function.run (/home/alejo/git/node_test/index.ts:12:50)
    at Object.<anonymous> (/home/alejo/git/node_test/index.ts:22:9)
    at Module.m._compile (/home/alejo/git/node_test/node_modules/ts-node/src/index.ts:1371:23)
    at Object.require.extensions.<computed> [as .ts] (/home/alejo/git/node_test/node_modules/ts-node/src/index.ts:1374:12)
    at main (/home/alejo/git/node_test/node_modules/ts-node/src/bin.ts:331:12)
    at Object.<anonymous> (/home/alejo/git/node_test/node_modules/ts-node/src/bin.ts:482:3) {
  name: 'Error'
}

Process finished with exit code 1

The same happens when trying with google chrome.

Sometimes I get a timeout error but it is the same result.

starting
/home/alejo/git/node_test/index.ts:12
        const browser: Browser =  await chromium.launch(launchOptions)
                                                 ^
browserType.launch: Timeout 30000ms exceeded.
=========================== logs ===========================
<launching> /usr/bin/chromium-browser 
<launched> pid=201225

I am using this environment:

node: v16.6.2
playwright-core: ^1.16.3
chromium-browser: 95.0.4638.69
google-chrome: 95.0.4638.69

Any help will be valuable

Upvotes: 3

Views: 7950

Answers (1)

Alejandro Vera
Alejandro Vera

Reputation: 377

Well, after a lot of trouble I found the solution...

I had to add this options to the launching

const launchOptions = {
        "headless": false,
        "executablePath": "/usr/bin/google-chrome",
        "args": [
        "--no-sandbox",
        "--no-zygote"]
    }

Upvotes: 2

Related Questions