puppeteer-browser-ready 1.3.8 → 1.4.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/README.md +5 -5
- package/dist/puppeteer-browser-ready.d.ts +1 -1
- package/dist/puppeteer-browser-ready.js +15 -15
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -88,9 +88,9 @@ import puppeteer from 'puppeteer';
|
|
|
88
88
|
import { browserReady } from 'puppeteer-browser-ready';
|
|
89
89
|
|
|
90
90
|
const handleResponse = (web) => {
|
|
91
|
-
console.
|
|
92
|
-
console.
|
|
93
|
-
console.
|
|
91
|
+
console.info('Hello, World!');
|
|
92
|
+
console.info('web fields:', Object.keys(web).join(', '));
|
|
93
|
+
console.info(`The HTML from ${web.location.href} is ${web.html.length} characters`,
|
|
94
94
|
`long and contains ${web.root.querySelectorAll('p').length} <p> tags.`);
|
|
95
95
|
return web;
|
|
96
96
|
};
|
|
@@ -223,11 +223,11 @@ By default Mocha allows a test 2,000 ms to complete before timing out with a fai
|
|
|
223
223
|
Web page load times can vary significantly, so it's sometimes a good idea to use the `timeout`
|
|
224
224
|
option to bump up the allowed test execution time.
|
|
225
225
|
|
|
226
|
-
Example configuration in **package.json** to allow
|
|
226
|
+
Example configuration in **package.json** to allow 7,000 ms:
|
|
227
227
|
```json
|
|
228
228
|
"scripts": {
|
|
229
229
|
"pretest": "run-scripts clean build",
|
|
230
|
-
"test": "mocha spec
|
|
230
|
+
"test": "mocha spec --timeout 7000"
|
|
231
231
|
},
|
|
232
232
|
```
|
|
233
233
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! puppeteer-browser-ready v1.
|
|
1
|
+
//! puppeteer-browser-ready v1.4.0 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import { Browser, HTTPResponse, Page } from 'puppeteer';
|
|
4
4
|
import { HTMLElement } from 'node-html-parser';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! puppeteer-browser-ready v1.
|
|
1
|
+
//! puppeteer-browser-ready v1.4.0 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import { parse } from 'node-html-parser';
|
|
4
4
|
import express from 'express';
|
|
@@ -7,7 +7,7 @@ import httpTerminator from 'http-terminator';
|
|
|
7
7
|
const browserReady = {
|
|
8
8
|
log(...args) {
|
|
9
9
|
const indent = typeof globalThis.describe === 'function' ? ' [' : '[';
|
|
10
|
-
console.
|
|
10
|
+
console.info(indent + new Date().toISOString() + ']', ...args);
|
|
11
11
|
},
|
|
12
12
|
startWebServer(options) {
|
|
13
13
|
const defaults = { folder: '.', port: 0, verbose: true, autoCleanup: true };
|
|
@@ -31,7 +31,7 @@ const browserReady = {
|
|
|
31
31
|
if (settings.verbose)
|
|
32
32
|
server.on('listening', logListening).on('close', logClose);
|
|
33
33
|
const cleanup = () => {
|
|
34
|
-
console.
|
|
34
|
+
console.info('[SIGINT]');
|
|
35
35
|
terminator.terminate();
|
|
36
36
|
};
|
|
37
37
|
if (settings.autoCleanup)
|
|
@@ -44,32 +44,32 @@ const browserReady = {
|
|
|
44
44
|
goto(url, options) {
|
|
45
45
|
const defaults = { parseHtml: true, verbose: false };
|
|
46
46
|
const settings = { ...defaults, ...options };
|
|
47
|
-
const
|
|
48
|
-
console.
|
|
47
|
+
const output = (label, msg) => settings.verbose &&
|
|
48
|
+
console.info(' ', Date.now() % 100000, label + ':'.padEnd(16 - label.length, ' '), msg);
|
|
49
49
|
const rootInfo = (root) => `${root.constructor.name}/${root.firstChild?.toString().trim()}`;
|
|
50
50
|
const web = async (browser) => {
|
|
51
|
-
log('Connected', browser.connected);
|
|
52
51
|
try {
|
|
52
|
+
output('[1/8] Connected', browser.connected);
|
|
53
53
|
const page = await browser.newPage();
|
|
54
|
-
|
|
54
|
+
output('[2/8] Page', url);
|
|
55
55
|
const response = await page.goto(url);
|
|
56
|
-
|
|
56
|
+
output('[3/8] Response', response?.url());
|
|
57
57
|
const status = response && response.status();
|
|
58
|
-
|
|
58
|
+
output('[4/8] Status', status);
|
|
59
59
|
const location = await page.evaluate(() => globalThis.location);
|
|
60
|
-
|
|
60
|
+
output('[5/8] Host', location.host);
|
|
61
61
|
const title = response && await page.title();
|
|
62
|
-
|
|
62
|
+
output('[6/8] Title', title);
|
|
63
63
|
const html = response && await response.text();
|
|
64
|
-
|
|
64
|
+
output('[7/8] Bytes', html?.length);
|
|
65
65
|
const root = html && settings.parseHtml ? parse(html) : null;
|
|
66
|
-
|
|
66
|
+
output('[8/8] DOM root', root ? rootInfo(root) : null);
|
|
67
67
|
return { browser, page, response, status, location, title, html, root };
|
|
68
68
|
}
|
|
69
69
|
catch (error) {
|
|
70
70
|
const status = browser.connected ? 'connected' : 'not connected';
|
|
71
|
-
console.
|
|
72
|
-
console.
|
|
71
|
+
console.info('[puppeteer-browser-ready]', settings, status);
|
|
72
|
+
console.info(error);
|
|
73
73
|
throw error;
|
|
74
74
|
}
|
|
75
75
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "puppeteer-browser-ready",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Simple utility to go to a URL and wait for the HTTP response",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -51,41 +51,41 @@
|
|
|
51
51
|
],
|
|
52
52
|
"build": [
|
|
53
53
|
"tsc",
|
|
54
|
-
"add-dist-header build dist"
|
|
55
|
-
"html-validator spec"
|
|
54
|
+
"add-dist-header build dist"
|
|
56
55
|
]
|
|
57
56
|
},
|
|
58
57
|
"scripts": {
|
|
59
58
|
"pretest": "run-scripts clean lint build",
|
|
60
|
-
"test": "mocha spec/*.spec.js --timeout 7000 --retries 1"
|
|
59
|
+
"test": "mocha spec/*.spec.js --timeout 7000 --retries 1",
|
|
60
|
+
"posttest": "html-validator spec"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"puppeteer": "^15 || ^16 || ^17 || ^18 || ^19.7 || ^20 || ^21 || ^22.8 || ^23 || ^24"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"express": "~
|
|
66
|
+
"express": "~5.1",
|
|
67
67
|
"http-terminator": "~3.2",
|
|
68
68
|
"node-html-parser": "~7.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@eslint/js": "~9.
|
|
71
|
+
"@eslint/js": "~9.38",
|
|
72
72
|
"@types/express": "~5.0",
|
|
73
73
|
"@types/mocha": "~10.0",
|
|
74
|
-
"@types/node": "~
|
|
74
|
+
"@types/node": "~24.9",
|
|
75
75
|
"@types/ws": "~8.18",
|
|
76
|
-
"add-dist-header": "~1.
|
|
76
|
+
"add-dist-header": "~1.5",
|
|
77
77
|
"assert-deep-strict-equal": "~1.2",
|
|
78
|
-
"copy-file-util": "~1.
|
|
78
|
+
"copy-file-util": "~1.3",
|
|
79
79
|
"copy-folder-util": "~1.1",
|
|
80
|
-
"eslint": "~9.
|
|
80
|
+
"eslint": "~9.38",
|
|
81
81
|
"jshint": "~2.13",
|
|
82
|
-
"mocha": "~11.
|
|
83
|
-
"open": "~10.
|
|
84
|
-
"puppeteer": "~24.
|
|
82
|
+
"mocha": "~11.7",
|
|
83
|
+
"open": "~10.2",
|
|
84
|
+
"puppeteer": "~24.27",
|
|
85
85
|
"rimraf": "~6.0",
|
|
86
86
|
"run-scripts-util": "~1.3",
|
|
87
|
-
"typescript": "~5.
|
|
88
|
-
"typescript-eslint": "~8.
|
|
89
|
-
"w3c-html-validator": "~
|
|
87
|
+
"typescript": "~5.9",
|
|
88
|
+
"typescript-eslint": "~8.46",
|
|
89
|
+
"w3c-html-validator": "~2.0"
|
|
90
90
|
}
|
|
91
91
|
}
|