puppeteer-browser-ready 1.2.2 → 1.3.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
CHANGED
|
@@ -91,7 +91,7 @@ const handleResponse = (web) => {
|
|
|
91
91
|
console.log('Hello, World!');
|
|
92
92
|
console.log('web fields:', Object.keys(web).join(', '));
|
|
93
93
|
console.log(`The HTML from ${web.location.href} is ${web.html.length} characters`,
|
|
94
|
-
`long and contains ${web
|
|
94
|
+
`long and contains ${web.root.querySelectorAll('p').length} <p> tags.`);
|
|
95
95
|
return web;
|
|
96
96
|
};
|
|
97
97
|
puppeteer.launch()
|
|
@@ -102,7 +102,7 @@ puppeteer.launch()
|
|
|
102
102
|
**Output:**
|
|
103
103
|
```
|
|
104
104
|
Hello, World!
|
|
105
|
-
web fields: browser, page, response, title, html,
|
|
105
|
+
web fields: browser, page, response, status, location, title, html, root
|
|
106
106
|
The HTML from https://pretty-print-json.js.org/ is 8200 characters
|
|
107
107
|
long and contains 7 <p> tags.
|
|
108
108
|
```
|
|
@@ -137,7 +137,7 @@ describe('The web page', () => {
|
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
it('has exactly one header, main, and footer', () => {
|
|
140
|
-
const actual =
|
|
140
|
+
const actual = getTags('body >*');
|
|
141
141
|
const expected = ['header', 'main', 'footer'];
|
|
142
142
|
assertDeepStrictEqual(actual, expected);
|
|
143
143
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
//! puppeteer-browser-ready v1.
|
|
1
|
+
//! puppeteer-browser-ready v1.3.0 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
|
|
2
2
|
|
|
3
|
-
/// <reference types="cheerio" />
|
|
4
3
|
import { Browser, HTTPResponse, Page } from 'puppeteer';
|
|
5
4
|
import { HTMLElement } from 'node-html-parser';
|
|
6
5
|
import { Server } from 'http';
|
|
@@ -29,11 +28,9 @@ export type Web = {
|
|
|
29
28
|
location: Location;
|
|
30
29
|
title: string | null;
|
|
31
30
|
html: string | null;
|
|
32
|
-
$: cheerio.Root | null;
|
|
33
31
|
root: HTMLElement | null;
|
|
34
32
|
};
|
|
35
33
|
export type BrowserReadySettings = {
|
|
36
|
-
addCheerio: boolean;
|
|
37
34
|
parseHtml: boolean;
|
|
38
35
|
verbose: boolean;
|
|
39
36
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
//! puppeteer-browser-ready v1.
|
|
1
|
+
//! puppeteer-browser-ready v1.3.0 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import { parse } from 'node-html-parser';
|
|
4
|
-
import cheerio from 'cheerio';
|
|
5
4
|
import express from 'express';
|
|
6
5
|
import httpTerminator from 'http-terminator';
|
|
7
6
|
// Package
|
|
@@ -43,10 +42,8 @@ const browserReady = {
|
|
|
43
42
|
return http.terminator.terminate();
|
|
44
43
|
},
|
|
45
44
|
goto(url, options) {
|
|
46
|
-
const defaults = {
|
|
45
|
+
const defaults = { parseHtml: true, verbose: false };
|
|
47
46
|
const settings = { ...defaults, ...options };
|
|
48
|
-
if (options?.addCheerio)
|
|
49
|
-
console.log('puppeteer-browser-ready: Option "addCheerio" is deprecated, use "parseHtml" instead.');
|
|
50
47
|
const log = (label, msg) => settings.verbose &&
|
|
51
48
|
console.log(' ', Date.now() % 100000, label + ':', msg);
|
|
52
49
|
const rootInfo = (root) => root.constructor.name + '/' + root.firstChild.toString();
|
|
@@ -65,10 +62,9 @@ const browserReady = {
|
|
|
65
62
|
log('Title', title);
|
|
66
63
|
const html = response && await response.text();
|
|
67
64
|
log('Bytes', html?.length);
|
|
68
|
-
const $ = html && settings.addCheerio ? cheerio.load(html) : null; //deprecated
|
|
69
65
|
const root = html && settings.parseHtml ? parse(html) : null;
|
|
70
66
|
log('DOM root', root ? rootInfo(root) : null);
|
|
71
|
-
return { browser, page, response, status, location, title, html,
|
|
67
|
+
return { browser, page, response, status, location, title, html, root };
|
|
72
68
|
}
|
|
73
69
|
catch (error) {
|
|
74
70
|
const status = browser.isConnected() ? 'connected' : 'not connected';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "puppeteer-browser-ready",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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",
|
|
@@ -85,13 +85,11 @@
|
|
|
85
85
|
"puppeteer": "^15 || ^16 || ^17 || ^18 || ^19.7 || ^20 || ^21"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"cheerio": "~1.0.0-rc.12",
|
|
89
88
|
"express": "~4.18",
|
|
90
89
|
"http-terminator": "~3.2",
|
|
91
90
|
"node-html-parser": "~6.1"
|
|
92
91
|
},
|
|
93
92
|
"devDependencies": {
|
|
94
|
-
"@types/cheerio": "~0.22",
|
|
95
93
|
"@types/express": "~4.17",
|
|
96
94
|
"@types/mocha": "~10.0",
|
|
97
95
|
"@types/node": "~20.6",
|