@link-assistant/web-capture 1.1.2 → 1.4.2
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/CHANGELOG.md +17 -14
- package/README.md +256 -146
- package/bin/web-capture.js +403 -6
- package/package.json +11 -4
- package/src/animation.js +283 -0
- package/src/archive.js +212 -0
- package/src/batch.js +180 -0
- package/src/browser.js +150 -111
- package/src/docx.js +182 -0
- package/src/figures.js +208 -0
- package/src/gdocs.js +333 -0
- package/src/image.js +65 -8
- package/src/index.js +15 -0
- package/src/latex.js +127 -0
- package/src/lib.js +226 -1
- package/src/localize-images.js +202 -0
- package/src/metadata.js +333 -0
- package/src/pdf.js +76 -0
- package/src/popups.js +171 -0
- package/src/postprocess.js +265 -0
- package/src/retry.js +48 -0
- package/src/themed-image.js +167 -0
- package/src/verify.js +312 -0
- package/tests/e2e/docker.test.js +51 -12
- package/tests/e2e/process.test.js +34 -10
- package/tests/fixtures/habr-articles.js +45 -0
- package/tests/integration/api-endpoints.test.js +231 -0
- package/tests/integration/habr-article.test.js +337 -0
- package/tests/mock/index.test.js +5 -3
- package/tests/unit/animation.test.js +33 -0
- package/tests/unit/batch.test.js +114 -0
- package/tests/unit/browser.test.js +38 -2
- package/tests/unit/figures.test.js +74 -0
- package/tests/unit/gdocs.test.js +203 -0
- package/tests/unit/latex.test.js +123 -0
- package/tests/unit/localize-images.test.js +78 -0
- package/tests/unit/metadata.test.js +140 -0
- package/tests/unit/postprocess.test.js +108 -0
- package/tests/unit/retry.test.js +111 -0
- package/tests/unit/verify.test.js +182 -0
- package/.github/workflows/release.yml +0 -294
- package/ARCHITECTURE.md +0 -982
- package/LICENSE +0 -24
- package/apply.sh +0 -166
- package/docs/market-analysis-2025-05-13.md +0 -64
- package/scripts/changeset-version.mjs +0 -38
- package/scripts/create-github-release.mjs +0 -93
- package/scripts/create-manual-changeset.mjs +0 -88
- package/scripts/format-github-release.mjs +0 -83
- package/scripts/format-release-notes.mjs +0 -218
- package/scripts/instant-version-bump.mjs +0 -121
- package/scripts/publish-to-npm.mjs +0 -128
- package/scripts/setup-npm.mjs +0 -37
- package/scripts/validate-changeset.mjs +0 -106
- package/scripts/version-and-commit.mjs +0 -237
package/CHANGELOG.md
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
# web-capture
|
|
1
|
+
# @link-assistant/web-capture
|
|
2
2
|
|
|
3
|
-
## 1.
|
|
3
|
+
## 1.4.2
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- 94c1953: Update lino-arguments to ^0.3.0, fix npm publish OIDC fallback, and align CI/CD workflows with reference repo best practices
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## 1.1.1
|
|
9
|
+
## 1.4.1
|
|
12
10
|
|
|
13
11
|
### Patch Changes
|
|
14
12
|
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
- 4570a2b: Fix CI/CD release pipeline: resolve git show path bug in version-and-commit.mjs where `git show origin/main:package.json` failed because git show uses repo-root-relative paths (should be `js/package.json`). Add npx-based fallback in setup-npm.mjs for Node.js 22.22.2 broken npm issue.
|
|
14
|
+
|
|
15
|
+
## 1.4.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- f464988: Add Google Docs document to Markdown capture support with API token authentication
|
|
20
|
+
|
|
21
|
+
## 1.3.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- 141458e: Implement all web capture best practices from meta-theory reference scripts (R1-R7): LaTeX formula extraction (Habr, KaTeX, MathJax), article metadata extraction, markdown post-processing pipeline, animation capture with loop detection, dual-theme screenshots, figure image extraction, markdown image localization, content verification with fuzzy matching, and batch processing with JSON/MJS configuration. Add enhanced HTML-to-markdown conversion with configurable options, 3 new API endpoints (/animation, /figures, /themed-image), and expanded CLI flags.
|
package/README.md
CHANGED
|
@@ -1,30 +1,69 @@
|
|
|
1
|
-
# web-capture
|
|
1
|
+
# web-capture (JavaScript/Node.js)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@link-assistant/web-capture)
|
|
4
|
+
[](https://www.npmjs.com/package/@link-assistant/web-capture)
|
|
5
|
+
[](https://github.com/link-assistant/web-capture/releases)
|
|
6
|
+
[](https://github.com/link-assistant/web-capture/actions/workflows/js.yml)
|
|
7
|
+
[](https://unlicense.org)
|
|
4
8
|
|
|
5
9
|
A CLI and microservice to fetch URLs and render them as:
|
|
6
10
|
|
|
7
11
|
- **HTML**: Rendered page content
|
|
8
12
|
- **Markdown**: Converted from HTML
|
|
9
|
-
- **PNG screenshot**:
|
|
13
|
+
- **PNG/JPEG screenshot**: Viewport or full-page capture with theme support
|
|
14
|
+
- **ZIP archive**: Markdown + locally downloaded images
|
|
15
|
+
- **PDF**: Print-quality document with embedded images
|
|
16
|
+
- **DOCX**: Word document with embedded images
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### From npm
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g @link-assistant/web-capture
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### From Source
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cd js
|
|
30
|
+
npm install
|
|
31
|
+
# or
|
|
32
|
+
yarn install
|
|
33
|
+
```
|
|
10
34
|
|
|
11
35
|
## Quick Start
|
|
12
36
|
|
|
13
37
|
### CLI Usage
|
|
14
38
|
|
|
15
39
|
```bash
|
|
16
|
-
# Install globally
|
|
17
|
-
npm install -g web-capture
|
|
18
|
-
|
|
19
40
|
# Capture a URL as HTML (output to stdout)
|
|
20
41
|
web-capture https://example.com
|
|
21
42
|
|
|
22
43
|
# Capture as Markdown and save to file
|
|
23
44
|
web-capture https://example.com --format markdown --output page.md
|
|
24
45
|
|
|
25
|
-
# Take a screenshot
|
|
46
|
+
# Take a PNG screenshot
|
|
26
47
|
web-capture https://example.com --format png --output screenshot.png
|
|
27
48
|
|
|
49
|
+
# Take a JPEG screenshot with custom quality
|
|
50
|
+
web-capture https://example.com --format jpeg --quality 60 --output screenshot.jpg
|
|
51
|
+
|
|
52
|
+
# Dark theme full-page screenshot
|
|
53
|
+
web-capture https://example.com --format png --theme dark --fullPage --output dark.png
|
|
54
|
+
|
|
55
|
+
# Custom viewport size
|
|
56
|
+
web-capture https://example.com --format png --width 1920 --height 1080 -o wide.png
|
|
57
|
+
|
|
58
|
+
# Download as PDF
|
|
59
|
+
web-capture https://example.com --format pdf --output page.pdf
|
|
60
|
+
|
|
61
|
+
# Download as DOCX
|
|
62
|
+
web-capture https://example.com --format docx --output page.docx
|
|
63
|
+
|
|
64
|
+
# Download as ZIP archive with local images
|
|
65
|
+
web-capture https://example.com --format archive --output site.zip
|
|
66
|
+
|
|
28
67
|
# Start as API server
|
|
29
68
|
web-capture --serve
|
|
30
69
|
|
|
@@ -32,200 +71,206 @@ web-capture --serve
|
|
|
32
71
|
web-capture --serve --port 8080
|
|
33
72
|
```
|
|
34
73
|
|
|
35
|
-
###
|
|
74
|
+
### Downloading Habr Articles
|
|
36
75
|
|
|
37
|
-
|
|
38
|
-
- **Markdown**: GET /markdown?url=<URL>
|
|
39
|
-
- **PNG screenshot**: GET /image?url=<URL>
|
|
40
|
-
|
|
41
|
-
## Installation
|
|
76
|
+
The service is tested against real Habr.com articles. Here are examples for each format:
|
|
42
77
|
|
|
43
78
|
```bash
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
yarn install
|
|
47
|
-
```
|
|
79
|
+
# Markdown (default: remote image links)
|
|
80
|
+
web-capture https://habr.com/en/articles/895896/ -f markdown -o article.md
|
|
48
81
|
|
|
49
|
-
|
|
82
|
+
# ZIP archive with local images (markdown format, default)
|
|
83
|
+
web-capture https://habr.com/en/articles/895896/ -f archive -o article.zip
|
|
50
84
|
|
|
51
|
-
|
|
85
|
+
# ZIP archive with local images (HTML format with CSS)
|
|
86
|
+
web-capture https://habr.com/en/articles/895896/ -f archive --documentFormat html -o article-html.zip
|
|
52
87
|
|
|
53
|
-
|
|
88
|
+
# Light theme full-page PNG
|
|
89
|
+
web-capture https://habr.com/en/articles/895896/ -f png --theme light --fullPage -o light.png
|
|
54
90
|
|
|
55
|
-
|
|
56
|
-
web-capture --
|
|
57
|
-
```
|
|
91
|
+
# Dark theme full-page PNG
|
|
92
|
+
web-capture https://habr.com/en/articles/895896/ -f png --theme dark --fullPage -o dark.png
|
|
58
93
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
| `--serve` | `-s` | Start as HTTP API server | - |
|
|
62
|
-
| `--port` | `-p` | Port to listen on | 3000 (or PORT env) |
|
|
63
|
-
|
|
64
|
-
### Capture Mode
|
|
94
|
+
# JPEG with 90% quality
|
|
95
|
+
web-capture https://habr.com/en/articles/895896/ -f jpeg --quality 90 -o article.jpg
|
|
65
96
|
|
|
66
|
-
|
|
97
|
+
# PDF with dark theme
|
|
98
|
+
web-capture https://habr.com/en/articles/895896/ -f pdf --theme dark -o article.pdf
|
|
67
99
|
|
|
68
|
-
|
|
69
|
-
web-capture
|
|
100
|
+
# DOCX with embedded images
|
|
101
|
+
web-capture https://habr.com/en/articles/895896/ -f docx -o article.docx
|
|
70
102
|
```
|
|
71
103
|
|
|
72
|
-
|
|
73
|
-
| ---------- | ----- | ----------------------------------------------------- | ---------------------------------------- |
|
|
74
|
-
| `--format` | `-f` | Output format: `html`, `markdown`/`md`, `image`/`png` | `html` |
|
|
75
|
-
| `--output` | `-o` | Output file path | stdout (text) or auto-generated (images) |
|
|
76
|
-
| `--engine` | `-e` | Browser engine: `puppeteer`, `playwright` | `puppeteer` (or BROWSER_ENGINE env) |
|
|
77
|
-
|
|
78
|
-
### Examples
|
|
104
|
+
## API Endpoints (Server Mode)
|
|
79
105
|
|
|
80
|
-
|
|
81
|
-
# Capture HTML to stdout
|
|
82
|
-
web-capture https://example.com
|
|
106
|
+
Start the server with `web-capture --serve` and use the endpoints below.
|
|
83
107
|
|
|
84
|
-
|
|
85
|
-
web-capture https://example.com -f markdown -o page.md
|
|
86
|
-
|
|
87
|
-
# Take screenshot with Playwright engine
|
|
88
|
-
web-capture https://example.com -f png -e playwright -o screenshot.png
|
|
108
|
+
### HTML Endpoint
|
|
89
109
|
|
|
90
|
-
|
|
91
|
-
|
|
110
|
+
```
|
|
111
|
+
GET /html?url=<URL>&engine=<ENGINE>
|
|
92
112
|
```
|
|
93
113
|
|
|
94
|
-
|
|
114
|
+
Returns the raw HTML content of the specified URL.
|
|
95
115
|
|
|
96
|
-
|
|
116
|
+
| Parameter | Required | Description | Default |
|
|
117
|
+
| --------- | -------- | ------------------------------------ | --------- |
|
|
118
|
+
| `url` | Yes | URL to fetch | - |
|
|
119
|
+
| `engine` | No | Browser engine: puppeteer/playwright | puppeteer |
|
|
97
120
|
|
|
98
|
-
|
|
99
|
-
- `yarn start` - Start the service using Docker Compose
|
|
121
|
+
### Markdown Endpoint
|
|
100
122
|
|
|
101
|
-
|
|
123
|
+
```
|
|
124
|
+
GET /markdown?url=<URL>
|
|
125
|
+
```
|
|
102
126
|
|
|
103
|
-
|
|
104
|
-
- `yarn test:watch` - Run tests in watch mode
|
|
105
|
-
- `yarn test:e2e` - Run end-to-end tests
|
|
106
|
-
- `yarn test:e2e:docker` - Run end-to-end tests against Docker container
|
|
107
|
-
- `yarn test:all` - Run all tests including build and e2e tests
|
|
127
|
+
Converts the HTML content of the specified URL to Markdown format.
|
|
108
128
|
|
|
109
|
-
|
|
129
|
+
| Parameter | Required | Description | Default |
|
|
130
|
+
| --------- | -------- | ------------ | ------- |
|
|
131
|
+
| `url` | Yes | URL to fetch | - |
|
|
110
132
|
|
|
111
|
-
|
|
133
|
+
### Image Endpoint
|
|
112
134
|
|
|
113
|
-
|
|
135
|
+
```
|
|
136
|
+
GET /image?url=<URL>&format=png&theme=dark&width=1920&height=1080&fullPage=true
|
|
137
|
+
```
|
|
114
138
|
|
|
115
|
-
|
|
116
|
-
- `yarn examples:javascript` - Run JavaScript example scripts
|
|
117
|
-
- `yarn examples` - Run all examples (requires build)
|
|
139
|
+
Returns a screenshot of the specified URL.
|
|
118
140
|
|
|
119
|
-
|
|
141
|
+
| Parameter | Required | Description | Default |
|
|
142
|
+
| --------------- | -------- | ---------------------------------------- | --------------- |
|
|
143
|
+
| `url` | Yes | URL to capture | - |
|
|
144
|
+
| `engine` | No | Browser engine: puppeteer/playwright | puppeteer |
|
|
145
|
+
| `format` | No | Image format: `png` (lossless) or `jpeg` | png |
|
|
146
|
+
| `quality` | No | JPEG quality 0-100 (ignored for PNG) | 80 |
|
|
147
|
+
| `width` | No | Viewport width in pixels | 1280 |
|
|
148
|
+
| `height` | No | Viewport height in pixels | 800 |
|
|
149
|
+
| `fullPage` | No | Capture full scrollable page | false |
|
|
150
|
+
| `theme` | No | Color scheme: `light`, `dark` | browser default |
|
|
151
|
+
| `dismissPopups` | No | Auto-close cookie/consent popups | true |
|
|
120
152
|
|
|
121
|
-
###
|
|
153
|
+
### Archive Endpoint
|
|
122
154
|
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
curl http://localhost:3000/html?url=https://example.com
|
|
155
|
+
```
|
|
156
|
+
GET /archive?url=<URL>&localImages=true&documentFormat=markdown
|
|
126
157
|
```
|
|
127
158
|
|
|
128
|
-
|
|
159
|
+
Returns a ZIP archive containing either `article.md` or `article.html` and asset directories (`images/`, `css/`).
|
|
129
160
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
161
|
+
| Parameter | Required | Description | Default |
|
|
162
|
+
| ---------------- | -------- | ---------------------------------------- | ---------- |
|
|
163
|
+
| `url` | Yes | URL to archive | - |
|
|
164
|
+
| `localImages` | No | Download images locally into the archive | true |
|
|
165
|
+
| `documentFormat` | No | Document format: `markdown` or `html` | `markdown` |
|
|
133
166
|
|
|
134
|
-
|
|
135
|
-
docker build -t web-capture .
|
|
136
|
-
docker run -p 3000:3000 web-capture
|
|
137
|
-
```
|
|
167
|
+
**Archive structure** (with `localImages=true`):
|
|
138
168
|
|
|
139
|
-
|
|
169
|
+
```
|
|
170
|
+
archive.zip
|
|
171
|
+
├── article.md # or article.html when documentFormat=html
|
|
172
|
+
├── images/
|
|
173
|
+
│ ├── image-1.png
|
|
174
|
+
│ ├── image-2.jpg
|
|
175
|
+
│ └── ...
|
|
176
|
+
└── css/ # only when documentFormat=html
|
|
177
|
+
├── style-1.css
|
|
178
|
+
└── ...
|
|
179
|
+
```
|
|
140
180
|
|
|
141
|
-
###
|
|
181
|
+
### PDF Endpoint
|
|
142
182
|
|
|
143
|
-
```
|
|
144
|
-
GET /
|
|
183
|
+
```
|
|
184
|
+
GET /pdf?url=<URL>&theme=light
|
|
145
185
|
```
|
|
146
186
|
|
|
147
|
-
Returns
|
|
187
|
+
Returns a PDF document rendered by the browser engine (all images embedded).
|
|
148
188
|
|
|
149
|
-
|
|
189
|
+
| Parameter | Required | Description | Default |
|
|
190
|
+
| --------------- | -------- | ------------------------------- | --------------- |
|
|
191
|
+
| `url` | Yes | URL to convert | - |
|
|
192
|
+
| `engine` | No | Browser engine | puppeteer |
|
|
193
|
+
| `width` | No | Viewport width in pixels | 1280 |
|
|
194
|
+
| `height` | No | Viewport height in pixels | 800 |
|
|
195
|
+
| `theme` | No | Color scheme: `light`, `dark` | browser default |
|
|
196
|
+
| `dismissPopups` | No | Auto-close popups before export | true |
|
|
150
197
|
|
|
151
|
-
|
|
152
|
-
- `engine` (optional): Browser engine to use (`puppeteer` or `playwright`). Default: `puppeteer`
|
|
198
|
+
### DOCX Endpoint
|
|
153
199
|
|
|
154
|
-
|
|
200
|
+
```
|
|
201
|
+
GET /docx?url=<URL>
|
|
202
|
+
```
|
|
155
203
|
|
|
156
|
-
|
|
157
|
-
# Using default Puppeteer engine
|
|
158
|
-
curl http://localhost:3000/html?url=https://example.com
|
|
204
|
+
Returns a DOCX document with embedded images.
|
|
159
205
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
206
|
+
| Parameter | Required | Description | Default |
|
|
207
|
+
| --------- | -------- | -------------- | ------- |
|
|
208
|
+
| `url` | Yes | URL to convert | - |
|
|
163
209
|
|
|
164
|
-
###
|
|
210
|
+
### Fetch/Stream Endpoints
|
|
165
211
|
|
|
166
|
-
```
|
|
167
|
-
GET /
|
|
212
|
+
```
|
|
213
|
+
GET /fetch?url=<URL>
|
|
214
|
+
GET /stream?url=<URL>
|
|
168
215
|
```
|
|
169
216
|
|
|
170
|
-
|
|
217
|
+
Proxy fetch and streaming proxy endpoints.
|
|
171
218
|
|
|
172
|
-
|
|
219
|
+
## CLI Reference
|
|
220
|
+
|
|
221
|
+
### Server Mode
|
|
173
222
|
|
|
174
223
|
```bash
|
|
175
|
-
|
|
224
|
+
web-capture --serve [--port <port>]
|
|
176
225
|
```
|
|
177
226
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
- `url` (required): The URL to capture
|
|
183
|
-
- `engine` (optional): Browser engine to use (`puppeteer` or `playwright`). Default: `puppeteer`
|
|
227
|
+
| Option | Short | Description | Default |
|
|
228
|
+
| --------- | ----- | ------------------------ | ------------------ |
|
|
229
|
+
| `--serve` | `-s` | Start as HTTP API server | - |
|
|
230
|
+
| `--port` | `-p` | Port to listen on | 3000 (or PORT env) |
|
|
184
231
|
|
|
185
|
-
|
|
232
|
+
### Capture Mode
|
|
186
233
|
|
|
187
234
|
```bash
|
|
188
|
-
|
|
189
|
-
curl http://localhost:3000/image?url=https://example.com > screenshot.png
|
|
190
|
-
|
|
191
|
-
# Using Playwright engine
|
|
192
|
-
curl http://localhost:3000/image?url=https://example.com&engine=playwright > screenshot.png
|
|
235
|
+
web-capture <url> [options]
|
|
193
236
|
```
|
|
194
237
|
|
|
238
|
+
| Option | Short | Description | Default |
|
|
239
|
+
| ------------------ | ----- | ---------------------------------------------- | ---------------------------------------- |
|
|
240
|
+
| `--format` | `-f` | Output format (see below) | `html` |
|
|
241
|
+
| `--output` | `-o` | Output file path | stdout (text) or auto-generated (images) |
|
|
242
|
+
| `--engine` | `-e` | Browser engine: `puppeteer`, `playwright` | `puppeteer` (or BROWSER_ENGINE env) |
|
|
243
|
+
| `--theme` | `-t` | Color scheme: `light`, `dark`, `no-preference` | browser default |
|
|
244
|
+
| `--width` | | Viewport width in pixels | 1280 |
|
|
245
|
+
| `--height` | | Viewport height in pixels | 800 |
|
|
246
|
+
| `--quality` | | JPEG quality 0-100 | 80 |
|
|
247
|
+
| `--fullPage` | | Capture full scrollable page | false |
|
|
248
|
+
| `--localImages` | | Download images locally in archive mode | true |
|
|
249
|
+
| `--documentFormat` | | Document format in archive: `markdown`, `html` | `markdown` |
|
|
250
|
+
|
|
251
|
+
**Supported formats:**
|
|
252
|
+
|
|
253
|
+
| Format | Description |
|
|
254
|
+
| ----------------- | ---------------------------------------- |
|
|
255
|
+
| `html` | Rendered HTML (default) |
|
|
256
|
+
| `markdown` / `md` | Markdown conversion |
|
|
257
|
+
| `image` / `png` | PNG screenshot (lossless) |
|
|
258
|
+
| `jpeg` | JPEG screenshot (configurable quality) |
|
|
259
|
+
| `pdf` | PDF with embedded images |
|
|
260
|
+
| `docx` | Word document with embedded images |
|
|
261
|
+
| `archive` / `zip` | ZIP archive with markdown + local images |
|
|
262
|
+
|
|
195
263
|
## Configuration
|
|
196
264
|
|
|
197
|
-
|
|
265
|
+
Configuration values are resolved with the following priority (highest to lowest):
|
|
198
266
|
|
|
199
267
|
1. **CLI arguments**: `--port 8080`
|
|
200
268
|
2. **Environment variables**: `PORT=8080`
|
|
201
|
-
3. **
|
|
202
|
-
4. **
|
|
203
|
-
5. **Built-in defaults**
|
|
204
|
-
|
|
205
|
-
### Configuration File (.lenv)
|
|
206
|
-
|
|
207
|
-
Create a `.lenv` file in your project root using Links Notation format:
|
|
208
|
-
|
|
209
|
-
```lenv
|
|
210
|
-
# Server configuration
|
|
211
|
-
PORT: 3000
|
|
212
|
-
|
|
213
|
-
# Browser engine (puppeteer or playwright)
|
|
214
|
-
BROWSER_ENGINE: puppeteer
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
### Using Custom Configuration Files
|
|
218
|
-
|
|
219
|
-
Specify a custom configuration file path:
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
web-capture --serve --configuration /path/to/custom.lenv
|
|
223
|
-
```
|
|
269
|
+
3. **Default .lenv file**: `.lenv` in the project root
|
|
270
|
+
4. **Built-in defaults**
|
|
224
271
|
|
|
225
272
|
### Environment Variables
|
|
226
273
|
|
|
227
|
-
All configuration options support environment variables:
|
|
228
|
-
|
|
229
274
|
```bash
|
|
230
275
|
# Set port via environment variable
|
|
231
276
|
export PORT=8080
|
|
@@ -243,26 +288,91 @@ The service supports both **Puppeteer** and **Playwright** browser engines:
|
|
|
243
288
|
- **Puppeteer**: Default engine, mature and well-tested
|
|
244
289
|
- **Playwright**: Alternative engine with similar capabilities
|
|
245
290
|
|
|
246
|
-
You can choose the engine using:
|
|
247
|
-
|
|
248
|
-
- CLI argument: `--engine playwright`
|
|
249
|
-
- Environment variable: `BROWSER_ENGINE=playwright`
|
|
250
|
-
- Configuration file: `BROWSER_ENGINE: playwright` in `.lenv`
|
|
251
|
-
|
|
252
291
|
**Supported engine values:**
|
|
253
292
|
|
|
254
293
|
- `puppeteer` or `pptr` - Use Puppeteer
|
|
255
294
|
- `playwright` or `pw` - Use Playwright
|
|
256
295
|
|
|
296
|
+
## Popup/Modal Dismissal
|
|
297
|
+
|
|
298
|
+
By default, the image, PDF, and archive endpoints automatically dismiss common popups before capture:
|
|
299
|
+
|
|
300
|
+
- Google Funding Choices consent dialogs
|
|
301
|
+
- Cookie consent banners
|
|
302
|
+
- Generic modals and overlays
|
|
303
|
+
- Fixed-position overlays covering content
|
|
304
|
+
|
|
305
|
+
Set `dismissPopups=false` to disable this behavior.
|
|
306
|
+
|
|
307
|
+
## Docker
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# Build and run using Docker Compose
|
|
311
|
+
docker compose up -d
|
|
312
|
+
|
|
313
|
+
# Or manually
|
|
314
|
+
docker build -t web-capture-js .
|
|
315
|
+
docker run -p 3000:3000 web-capture-js
|
|
316
|
+
```
|
|
317
|
+
|
|
257
318
|
## Development
|
|
258
319
|
|
|
259
|
-
|
|
320
|
+
### Available Commands
|
|
321
|
+
|
|
322
|
+
- `npm run dev` - Start the development server with hot reloading
|
|
323
|
+
- `npm run start` - Start the service using Docker Compose
|
|
324
|
+
- `npm test` - Run all unit tests
|
|
325
|
+
- `npm run lint` - Check code with ESLint
|
|
326
|
+
- `npm run format` - Format code with Prettier
|
|
327
|
+
|
|
328
|
+
### Testing
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
npm test # Run unit and integration tests
|
|
332
|
+
npm run test:e2e # Run end-to-end tests
|
|
333
|
+
npm run test:all # Run all tests including build
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Built With
|
|
260
337
|
|
|
261
338
|
- Express.js for the web server
|
|
262
|
-
- Puppeteer and Playwright for headless browser automation
|
|
339
|
+
- Puppeteer and Playwright for headless browser automation
|
|
263
340
|
- Turndown for HTML to Markdown conversion
|
|
341
|
+
- archiver for ZIP creation
|
|
342
|
+
- docx for DOCX generation
|
|
264
343
|
- Jest for testing
|
|
265
344
|
|
|
345
|
+
## Library Usage
|
|
346
|
+
|
|
347
|
+
You can also use web-capture as a Node.js library:
|
|
348
|
+
|
|
349
|
+
```javascript
|
|
350
|
+
import {
|
|
351
|
+
fetchHtml,
|
|
352
|
+
convertHtmlToMarkdown,
|
|
353
|
+
} from '@link-assistant/web-capture/src/lib.js';
|
|
354
|
+
import { createBrowser } from '@link-assistant/web-capture/src/browser.js';
|
|
355
|
+
import { dismissPopups } from '@link-assistant/web-capture/src/popups.js';
|
|
356
|
+
|
|
357
|
+
// Fetch and convert to markdown
|
|
358
|
+
const html = await fetchHtml('https://habr.com/en/articles/895896/');
|
|
359
|
+
const markdown = convertHtmlToMarkdown(
|
|
360
|
+
html,
|
|
361
|
+
'https://habr.com/en/articles/895896/'
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
// Take a themed screenshot
|
|
365
|
+
const browser = await createBrowser('playwright', { colorScheme: 'dark' });
|
|
366
|
+
const page = await browser.newPage();
|
|
367
|
+
await page.setViewport({ width: 1920, height: 1080 });
|
|
368
|
+
await page.goto('https://habr.com/en/articles/895896/', {
|
|
369
|
+
waitUntil: 'networkidle0',
|
|
370
|
+
});
|
|
371
|
+
await dismissPopups(page);
|
|
372
|
+
const buffer = await page.screenshot({ type: 'png', fullPage: true });
|
|
373
|
+
await browser.close();
|
|
374
|
+
```
|
|
375
|
+
|
|
266
376
|
## License
|
|
267
377
|
|
|
268
|
-
|
|
378
|
+
[Unlicense](../LICENSE) — This is free and unencumbered software released into the public domain. You are free to copy, modify, publish, use, compile, sell, or distribute this software for any purpose, commercial or non-commercial, and by any means. See [https://unlicense.org](https://unlicense.org) for details.
|