0.2.1 • Published 4 years ago

@cliqz/webextension-emulator v0.2.1

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

WebExtension Emulator

This library emulates the environment of a WebExtension inside a NodeJS VM. This enables:

  • Profiling and testing of the extension separately from a browser, and without the overheads of browser instrumentation.
  • Use node profiling tools to analyse extension performance
  • Generate synthetic extension benchmarks which run quickly.

This project is in the early stages, and most extension APIs only contain the minimum to allow an extension to run. We will be building out support for benchmarks of common patterns for testing our own extensions.

Usage

The following code loads a webextension inside the emulator and runs it for 10s. After this time we print a basic report of the extension run, including:

  • Resources loaded (both internal fetch and external webrequest), plus their sizes.
  • Amount of data saved in chrome.storage and how often it was written to.
  • The number of timers still registered after unloading the extension.
import Emulator from '@cliqz/webextension-emulator'
const sandbox = new Emulator('/path/to/webextension', {
  injectWebextensionPolyfill: true, // creates `browser` global with promisified APIs
  chromeStoragePath: './storage', // where to save chrome.storage data
  indexedDBPath: './idb', // where to save indexedDB data
  timeMultiplier: 1, // if virtual time should be modified
})
sandbox.createSandbox();
sandbox.startExtension();

setTimeout(() => {
  sandbox.stopExtension();
  sandbox.probeStorage();
  console.log(sandbox.probes);
}, 10000);

License

MIT.

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago