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

LHCI fails to run puppeteer script #321

Closed
vividhsv opened this issue May 21, 2020 · 2 comments
Closed

LHCI fails to run puppeteer script #321

vividhsv opened this issue May 21, 2020 · 2 comments

Comments

@vividhsv
Copy link

vividhsv commented May 21, 2020

LHCI version: 0.3.14

LHCI fails to run puppeteer script for authentication. Fails with error Unable to require 'puppeteer' for script, have you run 'npm i puppeteer'?.

Puppeteer is installed and made available using

yarn add  puppeteer --dev

Error

~/S/r/lighthouse ❯❯❯ lhci autorun
✅  .lighthouseci/ directory writable
✅  Configuration file found
✅  Chrome installation found
✅  Ancestor hash determinable
✅  LHCI server reachable
✅  LHCI server API-compatible
✅  LHCI server token valid
⚠️   LHCI server non-unique build for this hash
Healthcheck passed!

Error: Unable to require 'puppeteer' for script, have you run 'npm i puppeteer'?
    at PuppeteerManager._getBrowser (/usr/local/lib/node_modules/@lhci/cli/src/collect/puppeteer-manager.js:48:13)
    at PuppeteerManager.invokePuppeteerScriptForUrl (/usr/local/lib/node_modules/@lhci/cli/src/collect/puppeteer-manager.js:96:32)
    at Object.runCommand (/usr/local/lib/node_modules/@lhci/cli/src/collect/collect.js:189:23)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async run (/usr/local/lib/node_modules/@lhci/cli/src/cli.js:85:7)

lighthouserc.js

const AUT_BASE_URL = process.AUT_BASE_URL
const LIGHTHOUSE_SERVER_TOKEN = process.env.LIGHTHOUSE_SERVER_TOKEN
const LIGHTHOUSE_SERVER_URL = process.env.LIGHTHOUSE_SERVER_URL

module.exports = {
    ci: {
      collect: {
        "url": [
            `${AUT_BASE_URL}`
        ],
        "puppeteerScript": "login-script.js",
        "puppeteerLaunchOptions": {defaultViewport: null, args:["--disable-gpu --window-size=1920,1080", "--no-sandbox"], headless: true},
        "headful": false,
        "isSinglePageApplication": true,
        "disableStorageReset": true,
        "settings": {
            "output": "json",
            "maxWaitForFcp": 30000,
            "maxWaitForLoad": 45000,
            "throttlingMethod": "simulate",
            "auditMode": false,
            "gatherMode": false,
            "disableStorageReset": true,
            "emulatedFormFactor": "desktop",
            "internalDisableDeviceScreenEmulation": true,
            "channel": "devtools",
            "budgets": null,
            "locale": "en-US",
            "blockedUrlPatterns": null,
            "additionalTraceCategories": null,
            "extraHeaders": null,
            "precomputedLanternData": null,
            "onlyAudits": null,
            "onlyCategories": [
              "performance",
              "pwa",
              "best-practices",
              "accessibility",
            ],
            "skipAudits": null
          }
      },
      upload: {
        "target": "lhci",
        "token": LIGHTHOUSE_SERVER_TOKEN,
        "serverBaseUrl": LIGHTHOUSE_SERVER_URL
      },

    },
  };

login-script.js

/**
 * @param {puppeteer.Browser} browser
 * @param {{url: string, options: LHCI.CollectCommand.Options}} context
 */

const USER = process.env.USER
const PASSWORD = process.env.PASSWORD
const URL = process.env.URL

module.exports = async (browser, {url}) => {
    const page = await browser.newPage();
    await page.setViewport({ width: 1920, height: 1080 });
    await page.goto(context.url);
    await page.waitForSelector(locators.inputEmailInput, { visible: true });

    // Fill in and submit login form.
    const emailInput = await page.$(locators.inputEmailInput);
    await emailInput.type(USER);
    const passwordInput = await page.$(locators.inputEmailPassword);
    await passwordInput.type(PASSWORD);
    await Promise.all([
      page.$eval(locators.btnLogin, btn => btn.click()),
      page.waitForNavigation({ waitUntil: "networkidle2" })
    ]).catch(function(err) {
      console.log("Login Failed")
      process.exit(1)
    });

    await page.close();
  };
@vividhsv
Copy link
Author

Figured out. The issue was, since lhci was installed globally and lhci was looking for puppeteer globally.

@patrickhulce
Copy link
Collaborator

thanks for filing @vividhsv! this is a good case to catch though too so we'll handle it better in 0.4.0 :)

456d662

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

2 participants