puppeteer-browser-ready 1.2.0 → 1.2.1
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
|
@@ -5,7 +5,6 @@ _Simple utility to go to a URL and wait for the HTTP response_
|
|
|
5
5
|
|
|
6
6
|
[](https://github.com/center-key/puppeteer-browser-ready/blob/main/LICENSE.txt)
|
|
7
7
|
[](https://www.npmjs.com/package/puppeteer-browser-ready)
|
|
8
|
-
[](https://snyk.io/test/github/center-key/puppeteer-browser-ready)
|
|
9
8
|
[](https://github.com/center-key/puppeteer-browser-ready/actions/workflows/run-spec-on-push.yaml)
|
|
10
9
|
|
|
11
10
|
**puppeteer-browser-ready** is a helper utility to reduce the amount of boilerplate code needed
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! puppeteer-browser-ready v1.2.
|
|
1
|
+
//! puppeteer-browser-ready v1.2.1 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
|
|
2
2
|
|
|
3
3
|
/// <reference types="cheerio" />
|
|
4
4
|
import { Browser, HTTPResponse, Page } from 'puppeteer';
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
//! puppeteer-browser-ready v1.2.
|
|
1
|
+
//! puppeteer-browser-ready v1.2.1 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
|
|
2
2
|
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
3
|
import cheerio from 'cheerio';
|
|
13
4
|
import express from 'express';
|
|
14
5
|
import httpTerminator from 'http-terminator';
|
|
@@ -20,7 +11,7 @@ const browserReady = {
|
|
|
20
11
|
},
|
|
21
12
|
startWebServer(options) {
|
|
22
13
|
const defaults = { folder: '.', port: 0, verbose: true, autoCleanup: true };
|
|
23
|
-
const settings =
|
|
14
|
+
const settings = { ...defaults, ...options };
|
|
24
15
|
const server = express().use(express.static(settings.folder)).listen(settings.port);
|
|
25
16
|
const terminator = httpTerminator.createHttpTerminator({ server });
|
|
26
17
|
const port = () => server.address().port;
|
|
@@ -52,24 +43,24 @@ const browserReady = {
|
|
|
52
43
|
},
|
|
53
44
|
goto(url, options) {
|
|
54
45
|
const defaults = { addCheerio: true, verbose: false };
|
|
55
|
-
const settings =
|
|
46
|
+
const settings = { ...defaults, ...options };
|
|
56
47
|
const log = (label, msg) => settings.verbose &&
|
|
57
48
|
console.log(' ', Date.now() % 100000, label + ':', msg);
|
|
58
|
-
const web = (browser) =>
|
|
49
|
+
const web = async (browser) => {
|
|
59
50
|
log('Connected', browser.isConnected());
|
|
60
51
|
try {
|
|
61
|
-
const page =
|
|
52
|
+
const page = await browser.newPage();
|
|
62
53
|
log('Page....', url);
|
|
63
|
-
const response =
|
|
64
|
-
log('Response', response
|
|
54
|
+
const response = await page.goto(url);
|
|
55
|
+
log('Response', response?.url());
|
|
65
56
|
const status = response && response.status();
|
|
66
57
|
log('Status', status);
|
|
67
|
-
const location =
|
|
58
|
+
const location = await page.evaluate(() => globalThis.location);
|
|
68
59
|
log('Host', location.host);
|
|
69
|
-
const title = response &&
|
|
60
|
+
const title = response && await page.title();
|
|
70
61
|
log('Title', title);
|
|
71
|
-
const html = response &&
|
|
72
|
-
log('Bytes', html
|
|
62
|
+
const html = response && await response.text();
|
|
63
|
+
log('Bytes', html?.length);
|
|
73
64
|
const $ = html && settings.addCheerio ? cheerio.load(html) : null;
|
|
74
65
|
log('$', $ && $['fn'].constructor.name);
|
|
75
66
|
return { browser, page, response, status, location, title, html, $ };
|
|
@@ -80,15 +71,13 @@ const browserReady = {
|
|
|
80
71
|
console.log(error);
|
|
81
72
|
throw error;
|
|
82
73
|
}
|
|
83
|
-
}
|
|
74
|
+
};
|
|
84
75
|
return web;
|
|
85
76
|
},
|
|
86
|
-
close(web) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return web;
|
|
91
|
-
});
|
|
77
|
+
async close(web) {
|
|
78
|
+
if (web && web.browser)
|
|
79
|
+
await web.browser.close();
|
|
80
|
+
return web;
|
|
92
81
|
},
|
|
93
82
|
};
|
|
94
83
|
export { browserReady };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "puppeteer-browser-ready",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Simple utility to go to a URL and wait for the HTTP response",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"test": "mocha spec/*.spec.js --timeout 5000 --retries 1"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"puppeteer": "^
|
|
83
|
+
"puppeteer": "^15 || ^16 || ^17 || ^18 || ^19.7 || ^20 || ^21"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"cheerio": "~1.0.0-rc.12",
|
|
@@ -91,19 +91,19 @@
|
|
|
91
91
|
"@types/cheerio": "~0.22",
|
|
92
92
|
"@types/express": "~4.17",
|
|
93
93
|
"@types/mocha": "~10.0",
|
|
94
|
-
"@types/node": "~20.
|
|
94
|
+
"@types/node": "~20.4",
|
|
95
95
|
"@types/ws": "~8.5",
|
|
96
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
97
|
-
"@typescript-eslint/parser": "~
|
|
96
|
+
"@typescript-eslint/eslint-plugin": "~6.2",
|
|
97
|
+
"@typescript-eslint/parser": "~6.2",
|
|
98
98
|
"add-dist-header": "~1.1",
|
|
99
99
|
"assert-deep-strict-equal": "~1.1",
|
|
100
100
|
"copy-file-util": "~1.1",
|
|
101
101
|
"copy-folder-util": "~1.1",
|
|
102
|
-
"eslint": "~8.
|
|
102
|
+
"eslint": "~8.46",
|
|
103
103
|
"jshint": "~2.13",
|
|
104
104
|
"mocha": "~10.2",
|
|
105
105
|
"open": "~9.1",
|
|
106
|
-
"puppeteer": "~
|
|
106
|
+
"puppeteer": "~21.0",
|
|
107
107
|
"rimraf": "~5.0",
|
|
108
108
|
"run-scripts-util": "~1.2",
|
|
109
109
|
"typescript": "~5.1",
|