@push.rocks/smartbrowser 2.0.10 → 2.0.11
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/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/index.js +4 -3
- package/package.json +9 -9
- package/readme.hints.md +16 -1
- package/readme.md +76 -33
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/index.ts +3 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartbrowser',
|
|
6
|
-
version: '2.0.
|
|
6
|
+
version: '2.0.11',
|
|
7
7
|
description: 'A simplified Puppeteer wrapper for easy automation and testing tasks.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSwwQkFBMEI7SUFDaEMsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLHVFQUF1RTtDQUNyRixDQUFBIn0=
|
package/dist_ts/index.js
CHANGED
|
@@ -49,9 +49,10 @@ export class SmartBrowser {
|
|
|
49
49
|
await page.goto(urlArg, {
|
|
50
50
|
waitUntil: 'networkidle2',
|
|
51
51
|
});
|
|
52
|
-
const
|
|
52
|
+
const screenshotResult = await page.screenshot({
|
|
53
53
|
encoding: 'binary',
|
|
54
|
-
})
|
|
54
|
+
});
|
|
55
|
+
const screenshotBuffer = Buffer.from(screenshotResult);
|
|
55
56
|
await page.close();
|
|
56
57
|
return {
|
|
57
58
|
name: pageId,
|
|
@@ -83,4 +84,4 @@ export class SmartBrowser {
|
|
|
83
84
|
}
|
|
84
85
|
import { smartpuppeteer } from './smartbrowser.plugins.js';
|
|
85
86
|
export { smartpuppeteer };
|
|
86
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
87
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLDJCQUEyQixDQUFDO0FBRXJELE9BQU8sS0FBSyxVQUFVLE1BQU0sdUJBQXVCLENBQUM7QUFFcEQ7O0dBRUc7QUFDSCxNQUFNLE9BQU8sWUFBWTtJQUl2Qjs7T0FFRztJQUNJLEtBQUssQ0FBQyxLQUFLO1FBQ2hCLElBQUksQ0FBQyxlQUFlLEdBQUcsTUFBTSxPQUFPLENBQUMsY0FBYyxDQUFDLDBCQUEwQixFQUFFLENBQUM7UUFDakYsZ0VBQWdFO0lBQ2xFLENBQUM7SUFFRDs7T0FFRztJQUNLLEtBQUssQ0FBQyxjQUFjO1FBQzFCLElBQUksQ0FBQyxJQUFJLENBQUMsUUFBUSxFQUFFLENBQUM7WUFDbkIsSUFBSSxDQUFDLFFBQVEsR0FBRyxJQUFJLE9BQU8sQ0FBQyxRQUFRLENBQUMsUUFBUSxFQUFFLENBQUM7WUFDaEQsTUFBTSxJQUFJLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsZUFBZSxDQUFDLENBQUM7UUFDbEQsQ0FBQztJQUNILENBQUM7SUFFRDs7T0FFRztJQUNJLEtBQUssQ0FBQyxJQUFJO1FBQ2YsSUFBSSxJQUFJLENBQUMsUUFBUSxFQUFFLENBQUM7WUFDbEIsTUFBTSxJQUFJLENBQUMsUUFBUSxDQUFDLElBQUksRUFBRSxDQUFDO1lBQzNC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0FDekIsQ0FBQztJQUNKLENBQUM7SUFFRDs7OztPQUlHO0lBQ0ksS0FBSyxDQUFDLGNBQWMsQ0FBSSxNQUFjLEVBQUUsT0FBeUI7UUFDdEUsTUFBTSxJQUFJLEdBQUcsTUFBTSxJQUFJLENBQUMsZUFBZSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQ2xELElBQUksQ0FBQztZQUNILE1BQU0sSUFBSSxDQUFDLElBQUksQ0FBQyxNQUFNLEVBQUU7Z0JBQ3RCLFNBQVMsRUFBRSxjQUFjO2FBQzFCLENBQUMsQ0FBQztZQUNILE1BQU0sTUFBTSxHQUFHLE1BQU0sSUFBSSxDQUFDLFFBQVEsQ0FBQyxPQUFPLENBQUMsQ0FBQztZQUM1QyxPQUFPLE1BQU0sQ0FBQztRQUNoQixDQUFDO2dCQUFTLENBQUM7WUFDVCxJQUFJLENBQUM7Z0JBQUMsTUFBTSxJQUFJLENBQUMsS0FBSyxFQUFFLENBQUM7WUFBQyxDQUFDO1lBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxDQUFDLGdDQUFnQyxDQUFDLENBQUM7UUFDNUUsQ0FBQztJQUNILENBQUM7Q0FDRjtBQUVELE9BQU8sRUFBRSxjQUFjLEVBQUUsTUFBTSwyQkFBMkIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsY0FBYyxFQUFFLENBQUMifQ==
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartbrowser",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"description": "A simplified Puppeteer wrapper for easy automation and testing tasks.",
|
|
5
5
|
"main": "dist_ts/index.js",
|
|
6
6
|
"typings": "dist_ts/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "(tstest test/ --web)",
|
|
10
|
-
"build": "(tsbuild --web
|
|
10
|
+
"build": "(tsbuild --web)",
|
|
11
11
|
"buildDocs": "tsdoc"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"homepage": "https://code.foss.global/push.rocks/smartbrowser",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@push.rocks/smartdelay": "^3.0.5",
|
|
25
|
-
"@push.rocks/smartpdf": "^
|
|
26
|
-
"@push.rocks/smartpuppeteer": "^2.0.
|
|
25
|
+
"@push.rocks/smartpdf": "^4.2.0",
|
|
26
|
+
"@push.rocks/smartpuppeteer": "^2.0.5",
|
|
27
27
|
"@push.rocks/smartunique": "^3.0.9"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@git.zone/tsbuild": "^
|
|
31
|
-
"@git.zone/tsrun": "^
|
|
32
|
-
"@git.zone/tstest": "^
|
|
33
|
-
"@push.rocks/tapbundle": "^
|
|
34
|
-
"@types/node": "^
|
|
30
|
+
"@git.zone/tsbuild": "^4.3.0",
|
|
31
|
+
"@git.zone/tsrun": "^2.0.1",
|
|
32
|
+
"@git.zone/tstest": "^3.3.1",
|
|
33
|
+
"@push.rocks/tapbundle": "^6.0.3",
|
|
34
|
+
"@types/node": "^25.3.5"
|
|
35
35
|
},
|
|
36
36
|
"private": false,
|
|
37
37
|
"files": [
|
package/readme.hints.md
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
# Smartbrowser Hints
|
|
2
|
+
|
|
3
|
+
## Dependencies (as of 2026-03-09)
|
|
4
|
+
- `@push.rocks/smartpdf` v4.2.x: Has `SmartPdf.create()` factory method, but `new SmartPdf()` + `start(browser)` still works. Lazy init pattern used.
|
|
5
|
+
- `@push.rocks/smartpuppeteer` v2.x: `getEnvAwareBrowserInstance()` main entry point
|
|
6
|
+
- `@push.rocks/tapbundle` v6.x: No longer exports `expectAsync`, only `tap`, `expect`, `TapWrap`, `webhelpers`
|
|
7
|
+
- `@git.zone/tsbuild` v4.x: No `--allowimplicitany` flag (defaults to `noImplicitAny: false`), `--web` flag still passed but ignored if no ts_web
|
|
8
|
+
- `@git.zone/tstest` v3.3.x: Still supports `--web` flag, file suffix conventions changed (`.chromium.ts` for browser tests)
|
|
9
|
+
- `@types/node` v25.x: Latest Node.js type definitions
|
|
10
|
+
- Puppeteer `page.screenshot({ encoding: 'binary' })` returns `Uint8Array`, not `Buffer` - wrap with `Buffer.from()`
|
|
11
|
+
|
|
12
|
+
## Build
|
|
13
|
+
- `pnpm build` uses `tsbuild --web`
|
|
14
|
+
- `pnpm test` uses `tstest test/ --web`
|
|
15
|
+
- No ts_web directory exists in this project
|
|
16
|
+
- Duplicate dayjs versions in transitive deps cause build errors; fix with `pnpm dedupe`
|
package/readme.md
CHANGED
|
@@ -1,102 +1,145 @@
|
|
|
1
1
|
# @push.rocks/smartbrowser
|
|
2
|
-
simplified
|
|
2
|
+
A simplified Puppeteer wrapper for easy browser automation, PDF generation, screenshots, and page evaluation.
|
|
3
3
|
|
|
4
4
|
## Install
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
To install `@push.rocks/smartbrowser`, use the following command with your preferred package manager:
|
|
6
7
|
|
|
7
8
|
```bash
|
|
8
|
-
npm install @push.rocks/smartbrowser
|
|
9
|
+
npm install @push.rocks/smartbrowser
|
|
10
|
+
# or
|
|
11
|
+
pnpm install @push.rocks/smartbrowser
|
|
9
12
|
```
|
|
10
13
|
|
|
11
|
-
This
|
|
14
|
+
This module works with Node.js and requires a Chromium-compatible browser available in the environment. It uses `@push.rocks/smartpuppeteer` under the hood, which automatically detects your environment and configures the browser accordingly (including CI/Docker scenarios).
|
|
12
15
|
|
|
13
16
|
## Usage
|
|
14
17
|
|
|
15
|
-
`@push.rocks/smartbrowser`
|
|
18
|
+
`@push.rocks/smartbrowser` provides a high-level `SmartBrowser` class that wraps Puppeteer for common browser automation tasks: generating PDFs, capturing screenshots, and evaluating JavaScript on web pages.
|
|
16
19
|
|
|
17
20
|
### Getting Started
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
Import and initialize a `SmartBrowser` instance:
|
|
20
23
|
|
|
21
24
|
```typescript
|
|
22
25
|
import { SmartBrowser } from '@push.rocks/smartbrowser';
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Then, initialize and start the `SmartBrowser` instance:
|
|
26
26
|
|
|
27
|
-
```typescript
|
|
28
27
|
const smartBrowser = new SmartBrowser();
|
|
29
28
|
await smartBrowser.start();
|
|
30
29
|
```
|
|
31
30
|
|
|
32
31
|
### Generating a PDF from a Webpage
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
Generate a full-page PDF from any URL. The result includes a `Buffer` with the PDF contents:
|
|
35
34
|
|
|
36
35
|
```typescript
|
|
37
|
-
// Generate a PDF from a page
|
|
38
36
|
const pdfResult = await smartBrowser.pdfFromPage('https://example.com');
|
|
39
|
-
console.log(pdfResult.buffer); //
|
|
37
|
+
console.log(pdfResult.buffer); // PDF file buffer
|
|
38
|
+
console.log(pdfResult.name); // Generated name identifier
|
|
40
39
|
```
|
|
41
40
|
|
|
41
|
+
The PDF generation is powered by `@push.rocks/smartpdf`, which is lazily initialized on first use. This means the SmartPdf server is only started when you actually call `pdfFromPage()`, keeping resource usage minimal.
|
|
42
|
+
|
|
42
43
|
### Capturing a Screenshot of a Webpage
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
Capture a PNG screenshot of any webpage:
|
|
45
46
|
|
|
46
47
|
```typescript
|
|
47
|
-
// Capture a screenshot from a page
|
|
48
48
|
const screenshotResult = await smartBrowser.screenshotFromPage('https://example.com');
|
|
49
|
-
console.log(screenshotResult.buffer); //
|
|
49
|
+
console.log(screenshotResult.buffer); // Screenshot buffer (PNG)
|
|
50
|
+
console.log(screenshotResult.name); // Short unique identifier
|
|
51
|
+
console.log(screenshotResult.id); // Identifier with extension
|
|
50
52
|
```
|
|
51
53
|
|
|
52
54
|
### Evaluating JavaScript on a Webpage
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
Run arbitrary JavaScript inside a page context and retrieve the result:
|
|
55
57
|
|
|
56
58
|
```typescript
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return document.title; // Gets the title of the page
|
|
59
|
+
const pageTitle = await smartBrowser.evaluateOnPage('https://example.com', async () => {
|
|
60
|
+
return document.title;
|
|
60
61
|
});
|
|
61
|
-
console.log(pageTitle); //
|
|
62
|
+
console.log(pageTitle); // "Example Domain"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The `evaluateOnPage` method supports generic return types:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
const metrics = await smartBrowser.evaluateOnPage<{ width: number; height: number }>(
|
|
69
|
+
'https://example.com',
|
|
70
|
+
async () => {
|
|
71
|
+
return {
|
|
72
|
+
width: window.innerWidth,
|
|
73
|
+
height: window.innerHeight,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
console.log(metrics.width, metrics.height);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Pages are automatically closed after evaluation, even if an error occurs.
|
|
81
|
+
|
|
82
|
+
### Accessing the Underlying Puppeteer Browser
|
|
83
|
+
|
|
84
|
+
For advanced use cases, you can access the Puppeteer browser instance directly:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const page = await smartBrowser.headlessBrowser.newPage();
|
|
88
|
+
await page.goto('https://example.com');
|
|
89
|
+
// ... custom Puppeteer operations
|
|
90
|
+
await page.close();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
You can also import the `smartpuppeteer` module directly for lower-level browser management:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { smartpuppeteer } from '@push.rocks/smartbrowser';
|
|
97
|
+
|
|
98
|
+
const browser = await smartpuppeteer.getEnvAwareBrowserInstance();
|
|
62
99
|
```
|
|
63
100
|
|
|
64
101
|
### Shutting Down
|
|
65
102
|
|
|
66
|
-
|
|
103
|
+
Always stop the browser instance when done to free resources:
|
|
67
104
|
|
|
68
105
|
```typescript
|
|
69
106
|
await smartBrowser.stop();
|
|
70
107
|
```
|
|
71
108
|
|
|
72
|
-
|
|
109
|
+
This cleanly shuts down the SmartPdf server (if it was initialized) and closes the browser.
|
|
73
110
|
|
|
74
|
-
|
|
111
|
+
### Full Example
|
|
75
112
|
|
|
76
113
|
```typescript
|
|
77
114
|
import { SmartBrowser } from '@push.rocks/smartbrowser';
|
|
78
115
|
|
|
79
|
-
async function
|
|
116
|
+
async function main() {
|
|
80
117
|
const smartBrowser = new SmartBrowser();
|
|
81
118
|
await smartBrowser.start();
|
|
82
119
|
|
|
120
|
+
// Generate a PDF
|
|
83
121
|
const pdfResult = await smartBrowser.pdfFromPage('https://example.com');
|
|
84
|
-
console.log('PDF
|
|
122
|
+
console.log('PDF size:', pdfResult.buffer.length, 'bytes');
|
|
123
|
+
|
|
124
|
+
// Take a screenshot
|
|
125
|
+
const screenshot = await smartBrowser.screenshotFromPage('https://example.com');
|
|
126
|
+
console.log('Screenshot size:', screenshot.buffer.length, 'bytes');
|
|
85
127
|
|
|
86
|
-
|
|
87
|
-
|
|
128
|
+
// Evaluate JavaScript
|
|
129
|
+
const title = await smartBrowser.evaluateOnPage('https://example.com', async () => {
|
|
130
|
+
return document.title;
|
|
131
|
+
});
|
|
132
|
+
console.log('Page title:', title);
|
|
88
133
|
|
|
89
134
|
await smartBrowser.stop();
|
|
90
135
|
}
|
|
91
136
|
|
|
92
|
-
|
|
137
|
+
main();
|
|
93
138
|
```
|
|
94
139
|
|
|
95
|
-
In this guide, you've learned how to use `@push.rocks/smartbrowser` for common browser automation tasks. Follow this pattern to incorporate web automation into your applications efficiently.
|
|
96
|
-
|
|
97
140
|
## License and Legal Information
|
|
98
141
|
|
|
99
|
-
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
|
142
|
+
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
|
100
143
|
|
|
101
144
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
|
102
145
|
|
|
@@ -106,7 +149,7 @@ This project is owned and maintained by Task Venture Capital GmbH. The names and
|
|
|
106
149
|
|
|
107
150
|
### Company Information
|
|
108
151
|
|
|
109
|
-
Task Venture Capital GmbH
|
|
152
|
+
Task Venture Capital GmbH
|
|
110
153
|
Registered at District court Bremen HRB 35230 HB, Germany
|
|
111
154
|
|
|
112
155
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
package/ts/00_commitinfo_data.ts
CHANGED
package/ts/index.ts
CHANGED
|
@@ -58,9 +58,10 @@ export class SmartBrowser {
|
|
|
58
58
|
await page.goto(urlArg, {
|
|
59
59
|
waitUntil: 'networkidle2',
|
|
60
60
|
});
|
|
61
|
-
const
|
|
61
|
+
const screenshotResult = await page.screenshot({
|
|
62
62
|
encoding: 'binary',
|
|
63
|
-
})
|
|
63
|
+
});
|
|
64
|
+
const screenshotBuffer = Buffer.from(screenshotResult);
|
|
64
65
|
await page.close();
|
|
65
66
|
return {
|
|
66
67
|
name: pageId,
|