html-get 2.27.16 → 2.27.18
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/package.json +3 -3
- package/src/html.js +1 -1
- package/src/index.js +10 -0
- package/src/pdf/media.js +21 -6
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "html-get",
|
|
3
3
|
"description": "Get the HTML from any website, fine-tuned for correction & speed",
|
|
4
4
|
"homepage": "https://nicedoc.com/microlinkhq/html-get",
|
|
5
|
-
"version": "2.27.
|
|
5
|
+
"version": "2.27.18",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"bin": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"p-retry": "~4.6.0",
|
|
65
65
|
"tinyspawn": "~1.5.7",
|
|
66
66
|
"top-sites": "~1.1.224",
|
|
67
|
-
"unpdf": "~1.
|
|
67
|
+
"unpdf": "~2.1.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@browserless/test": "latest",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"typescript": "latest"
|
|
100
100
|
},
|
|
101
101
|
"engines": {
|
|
102
|
-
"node": ">=
|
|
102
|
+
"node": ">= 24"
|
|
103
103
|
},
|
|
104
104
|
"files": [
|
|
105
105
|
"bin",
|
package/src/html.js
CHANGED
|
@@ -30,7 +30,7 @@ const addHead = ({ $, url, headers, pdfMeta = {} }) => {
|
|
|
30
30
|
const charset = getCharset(headers)
|
|
31
31
|
const { domain } = parseUrl(url)
|
|
32
32
|
const head = $('head')
|
|
33
|
-
const title = pdfMeta.title || path.basename(url)
|
|
33
|
+
const title = pdfMeta.title || path.basename(url.split('#')[0])
|
|
34
34
|
const siteName = pdfMeta.publisher || domain
|
|
35
35
|
|
|
36
36
|
upsert(head.find('title'), tags, `<title>${escapeAttr(title)}</title>`)
|
package/src/index.js
CHANGED
|
@@ -26,6 +26,12 @@ const ABORT_TYPES = ['image', 'stylesheet', 'font']
|
|
|
26
26
|
|
|
27
27
|
const PDF_SIZE_TRESHOLD = 150 * 1024 // 150kb
|
|
28
28
|
|
|
29
|
+
// `URL#hash` is empty both when the fragment is missing and when it is
|
|
30
|
+
// empty. An empty fragment is still present on `href`, and it must win.
|
|
31
|
+
const inheritRequestFragment = (options, response) => {
|
|
32
|
+
if (!options.url.href.includes('#')) options.url.hash = new URL(response.url).hash
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
const fetch = PCancelable.fn(
|
|
30
36
|
async (
|
|
31
37
|
url,
|
|
@@ -36,6 +42,10 @@ const fetch = PCancelable.fn(
|
|
|
36
42
|
|
|
37
43
|
const req = got(url, {
|
|
38
44
|
...opts,
|
|
45
|
+
hooks: {
|
|
46
|
+
...opts.hooks,
|
|
47
|
+
beforeRedirect: [inheritRequestFragment].concat(opts.hooks?.beforeRedirect || [])
|
|
48
|
+
},
|
|
39
49
|
timeout: reqTimeout,
|
|
40
50
|
responseType: 'buffer'
|
|
41
51
|
})
|
package/src/pdf/media.js
CHANGED
|
@@ -5,6 +5,11 @@ const { deflateSync } = require('node:zlib')
|
|
|
5
5
|
const MIN_SIDE = 16
|
|
6
6
|
const MAX_PIXELS = 400 * 400
|
|
7
7
|
const MAX_LOGO_SIDE = 256
|
|
8
|
+
const RGBA_CHANNELS = 4
|
|
9
|
+
const PNG_COLOR_TYPE_RGBA = 6
|
|
10
|
+
const PNG_BIT_DEPTH = 8
|
|
11
|
+
const OPAQUE = 255
|
|
12
|
+
const TRANSPARENT = 0
|
|
8
13
|
|
|
9
14
|
const crcTable = new Uint32Array(256)
|
|
10
15
|
for (let n = 0; n < 256; n++) {
|
|
@@ -30,10 +35,10 @@ const chunk = (type, data) => {
|
|
|
30
35
|
return Buffer.concat([length, body, crc])
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
/** Encode raw
|
|
34
|
-
const toPngDataUri = ({ width, height,
|
|
38
|
+
/** Encode the raw RGBA pixels unpdf extracts into a PNG data URI. node:zlib only. */
|
|
39
|
+
const toPngDataUri = ({ width, height, data }) => {
|
|
35
40
|
const source = Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
|
36
|
-
const stride = width *
|
|
41
|
+
const stride = width * RGBA_CHANNELS
|
|
37
42
|
const raw = Buffer.alloc((stride + 1) * height)
|
|
38
43
|
for (let y = 0; y < height; y++) {
|
|
39
44
|
source.copy(raw, y * (stride + 1) + 1, y * stride, y * stride + stride)
|
|
@@ -41,8 +46,8 @@ const toPngDataUri = ({ width, height, channels, data }) => {
|
|
|
41
46
|
const ihdr = Buffer.alloc(13)
|
|
42
47
|
ihdr.writeUInt32BE(width, 0)
|
|
43
48
|
ihdr.writeUInt32BE(height, 4)
|
|
44
|
-
ihdr[8] =
|
|
45
|
-
ihdr[9] =
|
|
49
|
+
ihdr[8] = PNG_BIT_DEPTH
|
|
50
|
+
ihdr[9] = PNG_COLOR_TYPE_RGBA
|
|
46
51
|
const png = Buffer.concat([
|
|
47
52
|
Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]),
|
|
48
53
|
chunk('IHDR', ihdr),
|
|
@@ -52,6 +57,16 @@ const toPngDataUri = ({ width, height, channels, data }) => {
|
|
|
52
57
|
return `data:image/png;base64,${png.toString('base64')}`
|
|
53
58
|
}
|
|
54
59
|
|
|
60
|
+
/** An image mask has no color of its own: unpdf paints it opaque black on transparent. */
|
|
61
|
+
const isStencil = ({ data }) => {
|
|
62
|
+
for (let offset = 0; offset < data.length; offset += RGBA_CHANNELS) {
|
|
63
|
+
if (data[offset] || data[offset + 1] || data[offset + 2]) return false
|
|
64
|
+
const alpha = data[offset + 3]
|
|
65
|
+
if (alpha !== OPAQUE && alpha !== TRANSPARENT) return false
|
|
66
|
+
}
|
|
67
|
+
return true
|
|
68
|
+
}
|
|
69
|
+
|
|
55
70
|
const usable = images =>
|
|
56
71
|
images.filter(
|
|
57
72
|
img =>
|
|
@@ -60,7 +75,7 @@ const usable = images =>
|
|
|
60
75
|
img.width >= MIN_SIDE &&
|
|
61
76
|
img.height >= MIN_SIDE &&
|
|
62
77
|
img.width * img.height <= MAX_PIXELS &&
|
|
63
|
-
(img
|
|
78
|
+
!isStencil(img)
|
|
64
79
|
)
|
|
65
80
|
|
|
66
81
|
const isLogo = img =>
|