Skip to content

Error while run concurrently with bluebird #7104

Closed
@phuongnq

Description

@phuongnq

While running 2 instances of browser with Bluebird (http://bluebirdjs.com/docs/getting-started.html). I got following error:

{ Error: no known mark: lh:gather:loadBlank
    at Object.exports.stop (/Users/dummy.user/node_modules/marky/lib/marky.cjs.js:76:13)
    at Function.timeEnd (/Users/dummy.user/node_modules/lighthouse-logger/index.js:128:11)
    at Function.loadBlank (/Users/dummy.user/node_modules/lighthouse/lighthouse-core/gather/gather-runner.js:78:9)
    at processTicksAndRejections (internal/process/next_tick.js:81:5) friendlyMessage: undefined }
(node:11724) UnhandledPromiseRejectionWarning: Error: no known mark: lh:gather:loadBlank
    at Object.exports.stop (/Users/dummy.user/node_modules/marky/lib/marky.cjs.js:76:13)
    at Function.timeEnd (/Users/dummy.user/node_modules/lighthouse-logger/index.js:128:11)
    at Function.loadBlank (/Users/dummy.user/node_modules/lighthouse/lighthouse-core/gather/gather-runner.js:78:9)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
(node:11724) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11724) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The issue is about some log function from gather-runner.js. If I disable log functions const log = require('lighthouse-logger');, it works as expected.
Here is my sample code:

const puppeteer = require('puppeteer');
const lighthouse = require('lighthouse');
const {URL} = require('url');
const Promise = require('bluebird');

(async() => {

let browser1, browser2;
const task1 = () => (new Promise(async (resolve, reject) => {
    try {
        const url = 'https://github.com';
        // Use Puppeteer to launch headful Chrome and don't use its default 800x600 viewport.
        browser1 = await puppeteer.launch({
            headless: false,
            defaultViewport: null,
        });

        // Wait for Lighthouse to open url, then customize network conditions.
        // Note: this will re-establish these conditions when LH reloads the page. Think that's ok....
        browser1.on('targetchanged', async target => {
            const page = await target.page();

            function addStyleContent(content) {
            const style = document.createElement('style');
            style.type = 'text/css';
            style.appendChild(document.createTextNode(content));
            document.head.appendChild(style);
            }

            const css = '* {color: red}';

            if (page && page.url() === url) {
            // Note: can't use page.addStyleTag due to github.com/GoogleChrome/puppeteer/issues/1955.
            // Do it ourselves.
            const client = await page.target().createCDPSession();
            await client.send('Runtime.evaluate', {
                expression: `(${addStyleContent.toString()})('${css}')`
            });
            }
        });

        const {lhr} = await lighthouse(url, {
            port: (new URL(browser1.wsEndpoint())).port,
            output: 'json',
            logLevel: 'info',
        });
        console.log(`Lighthouse scores: ${Object.values(lhr.categories).map(c => c.score).join(', ')}`);
        await browser1.close();
        return resolve(true);
    } catch (ex) {
        console.log(ex);
        reject(ex);
    }
}));

const task2 = () => (new Promise(async (resolve, reject) => {
    try {
        const url = 'https://github.com';
        // Use Puppeteer to launch headful Chrome and don't use its default 800x600 viewport.
        browser2 = await puppeteer.launch({
            headless: false,
            defaultViewport: null,
        });

        // Wait for Lighthouse to open url, then customize network conditions.
        // Note: this will re-establish these conditions when LH reloads the page. Think that's ok....
        browser2.on('targetchanged', async target => {
            const page = await target.page();

            function addStyleContent(content) {
            const style = document.createElement('style');
            style.type = 'text/css';
            style.appendChild(document.createTextNode(content));
            document.head.appendChild(style);
            }

            const css = '* {color: red}';

            if (page && page.url() === url) {
            // Note: can't use page.addStyleTag due to github.com/GoogleChrome/puppeteer/issues/1955.
            // Do it ourselves.
            const client = await page.target().createCDPSession();
            await client.send('Runtime.evaluate', {
                expression: `(${addStyleContent.toString()})('${css}')`
            });
            }
        });

        const {lhr} = await lighthouse(url, {
            port: (new URL(browser2.wsEndpoint())).port,
            output: 'json',
            logLevel: 'info',
        });
        console.log(`Lighthouse scores: ${Object.values(lhr.categories).map(c => c.score).join(', ')}`);
        await browser2.close();
        return resolve(true);
    } catch (ex) {
        console.log(ex);
        reject(ex);
    }
}));

const tasks = [task1, task2];

console.log(tasks);

const res = await Promise.map(
    tasks,
    job => job(),
    { concurrency: 2 }
);
console.log(res);
console.log(browser1 === browser2);
})();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions