Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context conflict when starting unlighthouse twice for mobile and desktop #166

Open
BennyAlex opened this issue Oct 2, 2023 · 1 comment

Comments

@BennyAlex
Copy link

BennyAlex commented Oct 2, 2023

Describe the bug

I first run a desktop test, wich works fine, but when I want to start a second test for mobile I get this error:

file:///C:/Users/benny/work/lighthouse/node_modules/unctx/dist/index.mjs:6
      throw new Error("Context conflict");
            ^

Error: Context conflict

Any way to prevent this error or is it a bug?

Reproduction

export async function performTest(site, urls, device = 'desktop') {
  return new Promise(async (resolve, reject) => {
    const unlighthouse = await createUnlighthouse({
        site,
        urls,
        lighthouseOptions: {
          onlyCategories: ['performance', 'best-practices', 'accessibility', 'seo', 'pwa'],
        },
        puppeteerOptions: {
          args: ["--no-sandbox"],
          headless: true // headless works best,
        },
        server: {
          open: false
        },
        /* puppeteerCluster: {
             concurrency: 'CONCURRENCY_BROWSER', // which mode to use
             maxConcurrency: 1,
         },*/
        output: {
          json: true, // output json
          html: global.isDev // output html
        },
        debug: global.isDev, // output debug info
        cache: false, // disable caching of results
        scanner: {
          dynamicSampling: false, // no dynamic sampling
          maxRoutes: 100000, // max number of routes to scan
          samples: 1, // number of samples to take, higher does not work correctly currently
          crawler: false, // enable the crawler
          robotsTxt: false, // don't respect robots.txt
          sitemap: false, // don't respect sitemap.xml,
          skipJavascript: false, // don't skip javascript
          // exclude all pdfs and amp pages
          /*        exclude: [
                    '/.*?pdf',
                    '.*!/amp',
                    /!* 'en-*',*!/
                  ],*/
          // use desktop to scan
          device: device,
          // enable the throttling mode, good for getting more consistent results
          throttle: !global.isDev,
        },
        chrome: {
          useSystem: false // use the bundled chrome,
        }
      },
      {
        name: 'unlighthouse-provider-' + device,
      });
    
    const two_min = 2000 * 60;
    const timeOut = two_min + (urls.length * two_min);
    
    const timeout = setTimeout(() => {
      console.error('Maximum Timeout reached!');
      reject('Maximum Timeout reached!');
    }, timeOut);
    
    const {hooks} = unlighthouse;
    
    // listen to the worker-finished event
    hooks.hook('worker-finished', () => {
      console.log('All sites for ' + device + ' tested!');
      clearTimeout(timeout);
      resolve();
    });
    
    console.log('starting unlighthouse for', device);
    await unlighthouse.start(); // start the unlighthouse process, will not wait for it to finish, use hooks instead
  });
}

System / Nuxt Info

No response

@BennyAlex
Copy link
Author

@harlan-zw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant