Skip to content

Commit e1a81da

Browse files
committed
Release v1.2.2
1 parent d627efd commit e1a81da

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

dist/puppeteer-browser-ready.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
//! puppeteer-browser-ready v1.2.1 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
1+
//! puppeteer-browser-ready v1.2.2 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
22

33
/// <reference types="cheerio" />
44
import { Browser, HTTPResponse, Page } from 'puppeteer';
5+
import { HTMLElement } from 'node-html-parser';
56
import { Server } from 'http';
67
import { SuiteFunction } from 'mocha';
78
import httpTerminator from 'http-terminator';
@@ -29,9 +30,11 @@ export type Web = {
2930
title: string | null;
3031
html: string | null;
3132
$: cheerio.Root | null;
33+
root: HTMLElement | null;
3234
};
3335
export type BrowserReadySettings = {
3436
addCheerio: boolean;
37+
parseHtml: boolean;
3538
verbose: boolean;
3639
};
3740
export type BrowserReadyOptions = Partial<BrowserReadySettings>;

dist/puppeteer-browser-ready.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//! puppeteer-browser-ready v1.2.1 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
1+
//! puppeteer-browser-ready v1.2.2 ~~ https://github.com/center-key/puppeteer-browser-ready ~~ MIT License
22

3+
import { parse } from 'node-html-parser';
34
import cheerio from 'cheerio';
45
import express from 'express';
56
import httpTerminator from 'http-terminator';
@@ -42,10 +43,13 @@ const browserReady = {
4243
return http.terminator.terminate();
4344
},
4445
goto(url, options) {
45-
const defaults = { addCheerio: true, verbose: false };
46+
const defaults = { addCheerio: true, parseHtml: true, verbose: false };
4647
const settings = { ...defaults, ...options };
48+
if (options?.addCheerio)
49+
console.log('puppeteer-browser-ready: Option "addCheerio" is deprecated, use "parseHtml" instead.');
4750
const log = (label, msg) => settings.verbose &&
4851
console.log(' ', Date.now() % 100000, label + ':', msg);
52+
const rootInfo = (root) => root.constructor.name + '/' + root.firstChild.toString();
4953
const web = async (browser) => {
5054
log('Connected', browser.isConnected());
5155
try {
@@ -61,9 +65,10 @@ const browserReady = {
6165
log('Title', title);
6266
const html = response && await response.text();
6367
log('Bytes', html?.length);
64-
const $ = html && settings.addCheerio ? cheerio.load(html) : null;
65-
log('$', $ && $['fn'].constructor.name);
66-
return { browser, page, response, status, location, title, html, $ };
68+
const $ = html && settings.addCheerio ? cheerio.load(html) : null; //deprecated
69+
const root = html && settings.parseHtml ? parse(html) : null;
70+
log('DOM root', root ? rootInfo(root) : null);
71+
return { browser, page, response, status, location, title, html, $, root };
6772
}
6873
catch (error) {
6974
const status = browser.isConnected() ? 'connected' : 'not connected';

hello-world/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"dependencies": {
1717
"jshint": "~2.13",
18-
"puppeteer": "~21.1",
18+
"puppeteer": "~21.2",
1919
"puppeteer-browser-ready": "~1.2"
2020
}
2121
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "puppeteer-browser-ready",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Simple utility to go to a URL and wait for the HTTP response",
55
"license": "MIT",
66
"type": "module",

0 commit comments

Comments
 (0)