treosh / crux-api

A tiny (500 bytes) CrUX API wrapper that supports record & history API, handles errors, and provides types.
MIT License
59 stars 7 forks source link

Use googleapis to request Chrome UX Report API #3

Closed alekseykulikov closed 4 years ago

alekseykulikov commented 4 years ago

It's possible to use googleapis to request CrUX API.

A basic example:

// run: CRUX_KEY='...' node ./crux-with-googleapis.js

import { google } from 'googleapis'

const key = process.env.CRUX_KEY || 'no-key'
const crux = google.chromeuxreport('v1')
crux.records
  .queryRecord({ 
    auth: key, // authentication key
    requestBody: { origin: 'https://example.com' } // queryRecord params
  })
  .then((r) => {
     // r.data contains success/error response
     console.log(JSON.stringify(r.data, null, '  '))
  }, console.error)

How is crux-api different from googleapis? Pros:

Cons: