addyosmani / puppeteer-webperf

Automating Web Performance testing with Puppeteer 🎪
Apache License 2.0
1.81k stars 90 forks source link

Fixed device descriptior #9

Closed nucliweb closed 4 years ago

nucliweb commented 4 years ago

In this Pull Request

Problem

When you run the script cumulative-layout-shift.js and largest-contentful-paint.js you get an error.

➜ node largest-contentful-paint.js
TypeError: Cannot read property 'viewport' of undefined
    at Page.emulate (/Users/joan.leon/projects/PerfReviews/.../puppeteer-webperf/node_modules/puppeteer/lib/Page.js:541:38)
    at Page.<anonymous> (/Users/joan.leon/projects/PerfReviews/.../puppeteer-webperf/node_modules/puppeteer/lib/helper.js:95:27)
    at getLCP (/Users/joan.leon/projects/PerfReviews/.../puppeteer-webperf/largest-contentful-paint.js:55:16)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
LCP is: undefined

This error is because the DeviceDescriptors export the devices inside devicesMap object.

Solution

Add the key devicesMap to get devices, like:

const phone = devices.devicesMap['Nexus 5X'];
addyosmani commented 4 years ago

👍 Thank you for catching this, @nucliweb!