Giter Site home page Giter Site logo

macbre / phantomas Goto Github PK

View Code? Open in Web Editor NEW
2.3K 66.0 141.0 7 MB

Headless Chromium-based web performance metrics collector and monitoring tool

Home Page: https://www.npmjs.com/package/phantomas

License: BSD 2-Clause "Simplified" License

JavaScript 86.91% Shell 0.26% HTML 12.22% CSS 0.03% Dockerfile 0.58%
phantomas metrics javascript css webperf dom domquery jquery webperformance developer-tools

phantomas's Introduction

phantomas npm Inline docs code style: prettier Coverage Status CodeFactor

Headless Chromium-based modular web performance metrics collector. And why phantomas? Well, because :)

Requirements

Installation

Via npm

latest

npm install phantomas

This will install a recent version of Chromium supported by puppeteer module.

Via Docker

You can use phantomas Docker image:

docker pull macbre/phantomas:latest

Or you can fetch from GitHub's Containers registry

docker pull ghcr.io/macbre/phantomas:latest

Support

Foo

You can get support for phantomas via xs:code.

Usage example

const phantomas = require('phantomas'),
    promise = phantomas('http://example.com/');

promise.
    then(results => {
        console.log('Metrics', results.getMetrics());
        console.log('Offenders', results.getAllOffenders());
    }).
    catch(res => {
        console.error(res);
    });

// events handling
promise.on('recv', response => {
    console.log('Response: %s %s [%s]', response.method, response.url, response.contentType);
});

// including the custom one emitted by phantomas modules
promise.on('domQuery', (type, query) => {
        console.log('DOM query by %s - "%s"', type, query);
});

Or run ./examples/index.js.

Development version

To get the latest development version of phantomas (and install all required dependencies):

git clone [email protected]:macbre/phantomas.git
npm install

Running tests

First you need to start a local nginx container that will serve static assets used by integration tests suite. Then simply run npm t:

./test/server-start.sh
npm t

All pull requests that are filed for this repository will have tests run via GitHub Actions.

Having problems?

Please refer to /Troubleshooting.md

Features

  • modular approach - each metric is generated by a separate "module"
  • phantomas "core" acts as an events emitter that each module can hook into
  • in-depth metrics such as: number of events bound via jQuery, calls to window.writeor complex and duplicated CSS selectors (via analyze-css)
  • JSON as an output format
  • easy integration with other nodejs projects via CommonJS module (see API docs)
  • metrics can be emitted from JavaScript code of the page phantomas is run against (thanks to helper functions available in window.__phantomas)
  • device profiles allow phantomas to emulate mobile or tablet (by setting a proper user agent and viewport)

Contributors

All the contributors

Usage

phantomas comes as a CommonJS module (see API docs) that you can use in your nodejs projects.

You can also use it as a command line tool. Run phantomas -h for more details.

Metrics

Please refer to /docs/metrics.md file for a full, up-to-date list of all available modules and metrics that phantomas emits.

For developers

Let's make Web a bit faster!

Slides

Blogosphere

Introductions to phantomas and use cases:

Videos

Utilities

Use grunt to automate daily dev tasks, including your's application web performance, via these great tools:

Stargazers over time

Stargazers over time

phantomas's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phantomas's Issues

Introduce formatters interface

All output formatters (including TAP - #94 and Junit - #93) should have a common API and be written as plugins without being a dependency for the core.

Ability to run phantomas locally

Hi! Thanks for this fantastic library! It would be great if I could install and use phantomas locally. This way other modules could use this library as a dependency and extend it on npm. My use case is I'm writing a grunt plugin for performance metrics.

The other benefit is installing is more idiomatic to node.js where users are only asked to do:

npm install
npm test

with a package.json like:

{
  "scripts": {
    "test": "phantomas --url http://phantomjs.org"
  },
  "dependencies": {
    "phantomas": "0.8.1"
  }
}

I'd be happy to help out implementing this so it runs both globally and locally. Thanks!

Add phantomas.setMarkerMetric

Add phantomas.setMarkerMetric(name) (to both phantomas and browser scope).

This will set name metric with the value set to ms that elapsed from responseEnd event.

Add TAP output format

Add onDOMReadyEnd and windowOnLoadTimeEnd metrics

$ ./phantomas.js --url "http://elecena.pl/about" --verbose  | grep -i domready

20:38:43.884 onDOMready
20:38:43.885 DOM query: by tag name "body"
(...)
20:38:43.899 jQuery.ready called: from unknown fn: http://cdn.macbre.net/elecena/r513/package/bootstrap,elecena,ui,suggest,ads.js @ 1
20:38:43.899 console.log: %s: %s onDOMready 73 ms
* onDOMReadyTime: 58

onDOMReadyTime is reported as the moment when onDOMready event is fired. Add onDOMReadyEnd metric what will show when event processing finishes.

YepNope and Duplicate Requests (modules/requestStats)

Source: http://yepnopejs.com

YepNope is used for conditional loading of JavaScripts, and the way that it works, AFAIK, is that it will download the script, then load it from cache if it's necessary, causing another request in the logs, but with a filetype of "image," rather than "application/javascript" or "text/css".

To isolate actual dupes in scenarios where yepnope.js is used to add polyfills, we'd have to inspect requests file name and type to determine true dupes.

This is a fairly peculiar situation, since I don't have a good sense of to what degree yepnope is in use.

The reason it might be worth considering making modifications to the duplicate request checks is that it is integrated into Modernizr, which is relatively popular.

Analyzing CSS fails for some URLs

phantomas.js --url http://eurosport.yahoo.com/ --analyze-css  --verbose  | grep -i css
18:21:31.771 runScript: node /home/macbre/github/phantomas/analyze-css.js --url http://l2.yimg.com/zz/combo?yui:3.9.1/widget-base/assets/skins/sam/widget-base.css&yui:3.9.1/widget-stack/assets/skins/sam/widget-stack.css&yui:3.9.1/overlay/assets/skins/sam/overlay.css --json (pid #5136)
18:21:32.102 runScript: pid #5136 done in 333 ms
18:21:32.531 CSS: failed!

Failed page loading is not handled

When invalid URL is provided:

$ ./phantomas.js --url=http://foo.bar --verbose

an error from PhantomJS is not handled:

> Page loading finished ("fail")

Unknown Modules

Hi @macbre ,

Just tried to run the example.

phantomjs phantomas.js --url=https://github.com/macbre/phantomas  --verbose

Encountered the following error.

Unknown module ./lib/args for require()

Node: v0.8.4
PhantomJS: v1.6.1

Any suggestions?

Register film strip when page is loading

https://github.com/wesleyhales/loadreport/blob/master/loadreport.js#L226

  • enabled when --film-strip CLI option is passed
  • capture the page on:
    • loadStarted
    • send
    • recv
    • loadFinished
    • report
    • not often than every 75 ms
  • save to filmstrip/screenshot-$1-$2.png ($1 - timestamp of the page load started, $2 - time offset excluding time it took to render screenshots)

Please note that rendering each screenshot takes several hundreds ms. Consider increasing default timeout by providing --timeout option

Proposal: Page Errors Metric

Example URL: www.samsung.com

Good demo url for dumping a lot of garbage (console.*, warnings, and TypeErrors).

If it's possible to do so, might be good to track and emit events when encountered.

Proposal: Console.* and alert() warnings/count

Would it be worthwhile to add warnings on calls to console.* and alert (and totals) as a module?

At least console.log can have some impact on JS performance, IIRC from experiments on jsperf, so it might be worthwhile to flag in the same vein as document.write as bad practice in production code.

Report multiple requests to the same asset

Example:

http://www.wekton.pl/tranzystory/tranzystory-jednozlaczowe/

-> http://www.wekton.pl/assets/4be3ef2b/jui/css/base/jquery-ui.css
-> http://www.wekton.pl/assets/4be3ef2b/jquery.js

Logging from phantomas scope is broken

$ ./phantomas.js --url http://cnn.com --verbose

TypeError: '["msg:{\"type\":\"log\",\"data\":\"DOM event: \\\"DOMContentLoaded\\\" bound to \\\"#document\\\"\"}"]' is not a valid argument for 'Function.prototype.apply' (evaluating 'this.util.format.apply')

window.callPhantom causes PhantomJS crash

Mac OS X
Phantomas 0.6.1
PhantomJS 1.9.1
Node 0.8.18

I've seen crashes when providing the following URLs:

http://www.meetup.com
http://www.washingtonpost.com
http://www.cnn.com

So far the only commonality I've seen is that they're all using jQuery 1.7.1. The above URLs simply cause PhantomJS to fail.

The New York Times, which also uses jQuery 1.7.1, will display a series of errors, then either fail or complete. Maybe a race condition?

$ ./phantomas.js --url=http://nytimes.com

TypeError: 'undefined' is not an object (evaluating 'val.fn')

  phantomjs://webpage.evaluate():7
TypeError: '[object ElementConstructor]' is not a constructor (evaluating 'new Element("meta",{"name":"WT.z_fbc"})')

  http://js.nyt.com/js2/build/homepage/top.js:1
  http://js.nyt.com/js2/build/homepage/top.js:1
TypeError: 'undefined' is not a function (evaluating 'NYTD.loadEditionToggle()')

  http://www.nytimes.com/:77
TypeError: 'undefined' is not a function (evaluating '$("#spanABCRegion")')

  http://www.nytimes.com/:326
  http://www.nytimes.com/:337
ReferenceError: Can't find variable: NYT_HP_AVOID_MAYOR_PROMO

  http://www.nytimes.com/:552
TypeError: 'undefined' is not a function (evaluating 'e(document)')

  http://js.nyt.com/projects/assets/geoip_resolver/geotargeted_promo-e951aadc737a7470e13f9da6289fd63a.js:3
  http://js.nyt.com/projects/assets/geoip_resolver/geotargeted_promo-e951aadc737a7470e13f9da6289fd63a.js:3
TypeError: 'undefined' is not an object (evaluating 'e.extend')

  http://js.nyt.com/js2/build/video/players/extended/1.0/app.js:1
  http://www.nytimes.com/:841

// PhantomJS fails.

Introduce "metrics asserts"

Allow config.json to contain a set of asserts on selected metrics. Failed asserts should be reported and phantomas should exit with a correct code.

An example of asserts entry:

{
 "asserts": {
   "requests": 18,
   "evalCalls": 0,
   "eventsBound": 150
 }
}

Metric value should be not greater than provided value (metric value lte asserted value).

To be used by #93 and #94

Performance tests runner to be implemented in #120

See:

"Unknown module" error

When I try to run phantomas, I get the following error:

phantomas --url https://github.com/macbre/phantomas
Unknown module /usr/local/lib/node_modules/phantomas//lib/args for require()

Clarify the project name

Why is this called "phantomas"? I thought at first it may have been PhantomJS for ActionScript but clearly it is not. So... what's the "as" bit about? Can you clarify it in the README?

Interesting project, though!

~~James

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.