phantomas 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/phantomas.js +1 -2
- package/core/modules/requestsMonitor/requestsMonitor.js +1 -1
- package/core/scope.js +2 -1
- package/eslint.config.js +39 -0
- package/extensions/postLoadDelay/postLoadDelay.js +2 -2
- package/lib/browser.js +4 -3
- package/lib/index.js +10 -4
- package/modules/domComplexity/scope.js +7 -3
- package/package.json +7 -6
package/bin/phantomas.js
CHANGED
|
@@ -22,8 +22,7 @@ let options = parseArgv(process.argv);
|
|
|
22
22
|
if (typeof options.url !== "string" && typeof options.config === "undefined") {
|
|
23
23
|
debug("URL not provided - show help and leave");
|
|
24
24
|
getProgram().outputHelp();
|
|
25
|
-
process.
|
|
26
|
-
return;
|
|
25
|
+
process.exit(1);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
url = options.url;
|
|
@@ -40,7 +40,7 @@ function parseEntryUrl(entry) {
|
|
|
40
40
|
entry.protocol = false;
|
|
41
41
|
entry.isBlob = true;
|
|
42
42
|
} else {
|
|
43
|
-
parsed = new URL(entry.url)
|
|
43
|
+
parsed = new URL(entry.url);
|
|
44
44
|
|
|
45
45
|
entry.protocol = parsed.protocol.replace(":", ""); // e.g. "http:"
|
|
46
46
|
entry.domain = parsed.hostname;
|
package/core/scope.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* phantomas browser "scope" with helper code
|
|
3
3
|
*
|
|
4
|
-
* Code below is executed in page's "scope" (injected by
|
|
4
|
+
* Code below is executed in page's "scope" (injected by the scope.injectJs() helper)
|
|
5
5
|
*/
|
|
6
6
|
/* istanbul ignore next */
|
|
7
7
|
(function coreScope(scope) {
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
console,
|
|
115
115
|
"log:" + stringify(Array.prototype.slice.call(arguments))
|
|
116
116
|
);
|
|
117
|
+
// eslint-disable-next-line no-empty
|
|
117
118
|
} catch (e) {}
|
|
118
119
|
};
|
|
119
120
|
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const globals = require("globals");
|
|
2
|
+
const js = require("@eslint/js");
|
|
3
|
+
|
|
4
|
+
const eslintConfigPrettier = require("eslint-config-prettier");
|
|
5
|
+
|
|
6
|
+
module.exports = [
|
|
7
|
+
js.configs.recommended,
|
|
8
|
+
eslintConfigPrettier,
|
|
9
|
+
{
|
|
10
|
+
languageOptions: {
|
|
11
|
+
ecmaVersion: 2022,
|
|
12
|
+
sourceType: "script",
|
|
13
|
+
globals: {
|
|
14
|
+
// https://eslint.org/docs/latest/use/configure/language-options#predefined-global-variables
|
|
15
|
+
...globals.node,
|
|
16
|
+
...globals.browser,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
rules: {
|
|
20
|
+
"prefer-const": "off",
|
|
21
|
+
"no-console": "off",
|
|
22
|
+
"no-async-promise-executor": "off",
|
|
23
|
+
// https://eslint.org/docs/latest/rules/no-unused-vars
|
|
24
|
+
"no-unused-vars": [
|
|
25
|
+
"error",
|
|
26
|
+
{
|
|
27
|
+
vars: "all",
|
|
28
|
+
args: "after-used",
|
|
29
|
+
caughtErrors: "none", // ignore catch block variables
|
|
30
|
+
ignoreRestSiblings: false,
|
|
31
|
+
reportUsedIgnorePattern: false,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
ignores: ["coverage/**", "test/webroot/**"],
|
|
38
|
+
},
|
|
39
|
+
];
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
"use strict";
|
|
5
5
|
|
|
6
|
-
const { setTimeout } = require("timers/promises");
|
|
6
|
+
const { setTimeout: setTimeoutAsync } = require("timers/promises");
|
|
7
7
|
|
|
8
8
|
module.exports = function (phantomas) {
|
|
9
9
|
// e.g. --post-load-delay 5
|
|
@@ -19,6 +19,6 @@ module.exports = function (phantomas) {
|
|
|
19
19
|
phantomas.on("beforeClose", async () => {
|
|
20
20
|
phantomas.log("Sleeping for %d seconds", delay);
|
|
21
21
|
|
|
22
|
-
return
|
|
22
|
+
return setTimeoutAsync(delay * 1000);
|
|
23
23
|
});
|
|
24
24
|
};
|
package/lib/browser.js
CHANGED
|
@@ -148,10 +148,11 @@ Browser.prototype.init = async (phantomasOptions) => {
|
|
|
148
148
|
request._initiator = data.initiator;
|
|
149
149
|
|
|
150
150
|
networkDebug(
|
|
151
|
-
"Network.requestWillBeSent > %s %s [%s]",
|
|
151
|
+
"Network.requestWillBeSent > %s %s [%s] headers: %j",
|
|
152
152
|
request.method,
|
|
153
153
|
request.url,
|
|
154
|
-
request._initiator.type
|
|
154
|
+
request._initiator.type,
|
|
155
|
+
request.headers
|
|
155
156
|
);
|
|
156
157
|
|
|
157
158
|
this.events.emit("request", request); // @desc Emitted when page is about to send HTTP request
|
|
@@ -179,7 +180,7 @@ Browser.prototype.init = async (phantomasOptions) => {
|
|
|
179
180
|
var meta = responses[data.requestId];
|
|
180
181
|
|
|
181
182
|
/* istanbul ignore if */
|
|
182
|
-
if (typeof meta === "undefined") {
|
|
183
|
+
if (typeof meta?.response === "undefined") {
|
|
183
184
|
// the browser sometimes looses trace of a request, let's ignore.
|
|
184
185
|
networkDebug(
|
|
185
186
|
"Can't find request id %d in previous requests",
|
package/lib/index.js
CHANGED
|
@@ -89,7 +89,10 @@ function phantomas(url, opts) {
|
|
|
89
89
|
return page.$$(selector);
|
|
90
90
|
},
|
|
91
91
|
|
|
92
|
-
// @see https://
|
|
92
|
+
// @see https://pptr.dev/api/puppeteer.page.evaluateonnewdocument
|
|
93
|
+
// Adds a function which would be invoked in when:
|
|
94
|
+
// - the child frame is attached or navigated
|
|
95
|
+
// - the page is navigated
|
|
93
96
|
injectJs: async (script) => {
|
|
94
97
|
const debug = require("debug")("phantomas:injectJs");
|
|
95
98
|
|
|
@@ -98,7 +101,9 @@ function phantomas(url, opts) {
|
|
|
98
101
|
suffix = "}";
|
|
99
102
|
|
|
100
103
|
const preloadFile =
|
|
101
|
-
prefix +
|
|
104
|
+
prefix +
|
|
105
|
+
(await require("fs/promises").readFile(script, "utf8")) +
|
|
106
|
+
suffix;
|
|
102
107
|
|
|
103
108
|
await page.evaluateOnNewDocument(preloadFile);
|
|
104
109
|
|
|
@@ -117,8 +122,9 @@ function phantomas(url, opts) {
|
|
|
117
122
|
// @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageexposefunctionname-puppeteerfunction
|
|
118
123
|
await page.exposeFunction("__phantomas_emit", scope.emit);
|
|
119
124
|
|
|
120
|
-
// Inject helper code into the browser's scope
|
|
121
|
-
events.
|
|
125
|
+
// Inject helper code into the browser's scope (but only once!)
|
|
126
|
+
events.once("init", () => {
|
|
127
|
+
debug("onInit: injecting the core/scope.js ...");
|
|
122
128
|
scope.injectJs(__dirname + "/../core/scope.js");
|
|
123
129
|
});
|
|
124
130
|
|
|
@@ -92,13 +92,17 @@
|
|
|
92
92
|
})();
|
|
93
93
|
|
|
94
94
|
// count <iframe> tags
|
|
95
|
-
document.querySelectorAll("iframe")
|
|
96
|
-
|
|
95
|
+
const iframes = document.querySelectorAll("iframe");
|
|
96
|
+
phantomas.setMetric("iframesCount", iframes.length); // @desc number of iframe nodes
|
|
97
|
+
|
|
98
|
+
for (const iframe of iframes) {
|
|
99
|
+
phantomas.log(`iframe: ${iframe.src}`);
|
|
100
|
+
|
|
97
101
|
phantomas.addOffender("iframesCount", {
|
|
98
102
|
element: phantomas.getDOMPath(iframe),
|
|
99
103
|
url: iframe.src,
|
|
100
104
|
});
|
|
101
|
-
}
|
|
105
|
+
}
|
|
102
106
|
|
|
103
107
|
phantomas.spyEnabled(true);
|
|
104
108
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phantomas",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"author": "macbre <maciej.brencz@gmail.com> (http://macbre.net)",
|
|
5
5
|
"description": "Headless Chromium-based web performance metrics collector and monitoring tool",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -34,14 +34,15 @@
|
|
|
34
34
|
"decamelize": "^5.0.0",
|
|
35
35
|
"fast-stats": "0.0.6",
|
|
36
36
|
"js-yaml": "^4.0.0",
|
|
37
|
-
"puppeteer": "^
|
|
37
|
+
"puppeteer": "^23.0.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
+
"@eslint/js": "^9.3.0",
|
|
40
41
|
"@jest/globals": "^28.0.0",
|
|
41
|
-
"eslint": "^
|
|
42
|
-
"eslint-config-prettier": "^
|
|
43
|
-
"eslint-plugin-node": "^11.1.0",
|
|
42
|
+
"eslint": "^9.3.0",
|
|
43
|
+
"eslint-config-prettier": "^9.1.0",
|
|
44
44
|
"glob": "^8.0.1",
|
|
45
|
+
"globals": "^15.3.0",
|
|
45
46
|
"jest": "^28.0.0",
|
|
46
47
|
"prettier": "2.7.1"
|
|
47
48
|
},
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"coverageThreshold": {
|
|
63
64
|
"global": {
|
|
64
65
|
"statements": 89,
|
|
65
|
-
"branches":
|
|
66
|
+
"branches": 80,
|
|
66
67
|
"functions": 89,
|
|
67
68
|
"lines": 89
|
|
68
69
|
}
|