Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastly/performance-observer-polyfill

Package Overview
Dependencies
Maintainers
51
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastly/performance-observer-polyfill

🔎 PerformanceObserver Polyfill <img alt="Travis" src="https://img.shields.io/travis/fastly/performance-obs

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
increased by53.92%
Maintainers
51
Weekly downloads
 
Created
Source

🔎 PerformanceObserver Polyfill

Travis gzip size

The PerformanceObserver interface is a JavaScript API that can be used to observe the Performance Timeline to be notified of new performance metrics as they are recorded.

This polyfill allows consumers to use the PerformanceObserver interface within browser environments, which have basic Performance Timeline support (I.e. window.performance.getEntries()), but don't have observer support.

The polyfill works by falling back to polling the Performance Timeline on a given interval and calling all subscribed observers with the resulting set of entires.

Installation

npm install --save @fastly/performance-observer-polyfill

Usage:

As a polyfill

This automatically "installs" PerformanceObserverPolyfill as window.PerformanceObserver() if it detects PerformanceObserver isn't supported:

import '@fastly/performance-observer-polyfill/polyfill'

// PerformanceObserver is now available globally!
const observer = new PerformanceObserver((list) => {});
observer.observe({entryTypes: ['resource']});

Usage: As a ponyfill

With a module bundler like rollup or webpack, you can import @fastly/performance-observer-polyfill to use in your code without modifying any globals:

// using JS Modules:
import PerformanceObserver from '@fastly/performance-observer-polyfill'

// or using CommonJS:
const PerformanceObserver = require('@fastly/performance-observer-polyfill')

// usage:
const observer = new PerformanceObserver((list) => {});
observer.observe({entryTypes: ['resource']})

Caveats

As the polyfill implements the PerformanceObserver interface by falling back to polling the Performance Timeline via a call to window.performance.getEntries() we are limited to only expose timeline entry types that are supported by getEntries(). Therefore the polyfill can only be used to observe the entry types: navigation, resource and mark. Newer entry types such as paint are only exposed by the native PerformanceObserver implementation and thus not polyfillable.

Development

Requirements

  • Node.js >= 10

Install

git clone git@github.com:fastly/performance-observer-polyfill.git
cd performance-observer-polyfill
npm install
npm run build

Running

Most actions you'd like to perform whilst developing performance-observer-polyfill are defined as NPM scripts tasks and can be invoked using npm run {task}.

A list of all commands and their description can be found below.

NameDescription
buildCompiles the application for production environments
build:devCompiles the application for development
lintLints the source files for style errors using ESLint and automatically formats the source files using prettier
testRuns the unit test suite

License

MIT

Keywords

FAQs

Package last updated on 23 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc