@push.rocks/smartbrowser 2.0.10 → 3.0.0

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.
@@ -0,0 +1,3 @@
1
+ export { LiveBrowserCanvasRenderer } from './classes.livebrowsercanvasrenderer.js';
2
+ export type * from './interfaces.livebrowsercanvas.js';
3
+ export type { ILiveBrowserError, ILiveBrowserErrorEvent, ILiveBrowserFrame, ILiveBrowserFrameAcknowledgement, ILiveBrowserFrameAcknowledgementRequest, ILiveBrowserFrameEvent, ILiveBrowserInputBase, ILiveBrowserInsertTextInput, ILiveBrowserKeyInput, ILiveBrowserModifierState, ILiveBrowserMouseInput, ILiveBrowserScreencastMetadata, ILiveBrowserState, ILiveBrowserStateEvent, ILiveBrowserTabState, ILiveBrowserViewport, ILiveBrowserWheelInput, TLiveBrowserEvent, TLiveBrowserEventListener, TLiveBrowserImageFormat, TLiveBrowserStatus, TLiveBrowserTabStatus, } from '@push.rocks/smartpuppeteer';
@@ -0,0 +1,2 @@
1
+ export { LiveBrowserCanvasRenderer } from './classes.livebrowsercanvasrenderer.js';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90c193ZWIvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sd0NBQXdDLENBQUMifQ==
@@ -0,0 +1,29 @@
1
+ import type { ILiveBrowserFrame, ILiveBrowserFrameAcknowledgement, ILiveBrowserFrameAcknowledgementRequest, ILiveBrowserInsertTextInput, ILiveBrowserKeyInput, ILiveBrowserMouseInput, ILiveBrowserState, ILiveBrowserViewport, ILiveBrowserWheelInput, TLiveBrowserEventListener } from '@push.rocks/smartpuppeteer';
2
+ export interface ILiveBrowserCanvasClient {
3
+ getState(): ILiveBrowserState;
4
+ onEvent(listenerArg: TLiveBrowserEventListener): () => void;
5
+ acknowledgeFrame(requestArg: ILiveBrowserFrameAcknowledgementRequest): Promise<ILiveBrowserFrameAcknowledgement>;
6
+ setViewport(viewportArg: ILiveBrowserViewport): Promise<void>;
7
+ dispatchMouse(inputArg: ILiveBrowserMouseInput): Promise<void>;
8
+ dispatchWheel(inputArg: ILiveBrowserWheelInput): Promise<void>;
9
+ dispatchKey(inputArg: ILiveBrowserKeyInput): Promise<void>;
10
+ insertText(inputArg: ILiveBrowserInsertTextInput): Promise<void>;
11
+ }
12
+ export type TLiveBrowserCanvasErrorCode = 'frame_acknowledgement_failed' | 'frame_render_failed' | 'input_dispatch_failed' | 'input_queue_capacity_exceeded' | 'remote_browser_error' | 'renderer_callback_failed' | 'renderer_cleanup_failed' | 'viewport_update_failed';
13
+ export interface ILiveBrowserCanvasError {
14
+ code: TLiveBrowserCanvasErrorCode;
15
+ message: string;
16
+ cause?: unknown;
17
+ frame?: ILiveBrowserFrame;
18
+ }
19
+ export interface ILiveBrowserCanvasRendererOptions {
20
+ canvas: HTMLCanvasElement;
21
+ client: ILiveBrowserCanvasClient;
22
+ focusTarget?: HTMLElement;
23
+ resizeTarget?: Element;
24
+ getDeviceScaleFactor?: () => number;
25
+ operationTimeoutMs?: number;
26
+ frameDecodeTimeoutMs?: number;
27
+ onError?: (errorArg: ILiveBrowserCanvasError) => void;
28
+ onFrameRendered?: (frameArg: ILiveBrowserFrame) => void;
29
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlcy5saXZlYnJvd3NlcmNhbnZhcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzX3dlYi9pbnRlcmZhY2VzLmxpdmVicm93c2VyY2FudmFzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
package/license.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2016 Task Venture Capital GmbH <hello@task.vc>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/package.json CHANGED
@@ -1,49 +1,56 @@
1
1
  {
2
2
  "name": "@push.rocks/smartbrowser",
3
- "version": "2.0.10",
3
+ "version": "3.0.0",
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
- "scripts": {
9
- "test": "(tstest test/ --web)",
10
- "build": "(tsbuild --web --allowimplicitany)",
11
- "buildDocs": "tsdoc"
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist_ts/index.js",
11
+ "types": "./dist_ts/index.d.ts"
12
+ },
13
+ "./web": {
14
+ "import": "./dist_ts_web/index.js",
15
+ "types": "./dist_ts_web/index.d.ts"
16
+ }
17
+ },
18
+ "engines": {
19
+ "node": ">=22.12.0"
12
20
  },
13
21
  "repository": {
14
22
  "type": "git",
15
23
  "url": "https://code.foss.global/push.rocks/smartbrowser.git"
16
24
  },
17
- "author": "Lossless GmbH",
25
+ "author": "Task Venture Capital GmbH <hello@task.vc>",
18
26
  "license": "MIT",
19
27
  "bugs": {
20
- "url": "https://gitlab.com/pushrocks/smartbrowser/issues"
28
+ "url": "https://code.foss.global/push.rocks/smartbrowser/issues"
21
29
  },
22
30
  "homepage": "https://code.foss.global/push.rocks/smartbrowser",
23
31
  "dependencies": {
24
- "@push.rocks/smartdelay": "^3.0.5",
25
- "@push.rocks/smartpdf": "^3.1.8",
26
- "@push.rocks/smartpuppeteer": "^2.0.0",
27
- "@push.rocks/smartunique": "^3.0.9"
32
+ "@push.rocks/smartdelay": "^3.1.0",
33
+ "@push.rocks/smartpdf": "^5.0.1",
34
+ "@push.rocks/smartpuppeteer": "^2.1.0",
35
+ "@push.rocks/smartunique": "^3.0.10"
28
36
  },
29
37
  "devDependencies": {
30
- "@git.zone/tsbuild": "^2.2.0",
31
- "@git.zone/tsrun": "^1.3.3",
32
- "@git.zone/tstest": "^1.0.90",
33
- "@push.rocks/tapbundle": "^5.5.4",
34
- "@types/node": "^22.10.4"
38
+ "@git.zone/tsbuild": "^4.4.2",
39
+ "@git.zone/tsrun": "^2.0.6",
40
+ "@git.zone/tstest": "^4.0.0",
41
+ "@types/node": "^26.1.2"
35
42
  },
36
43
  "private": false,
37
44
  "files": [
38
45
  "ts/**/*",
39
46
  "ts_web/**/*",
40
- "dist/**/*",
41
47
  "dist_*/**/*",
42
48
  "dist_ts/**/*",
43
49
  "dist_ts_web/**/*",
44
50
  "assets/**/*",
45
51
  "cli.js",
46
- "npmextra.json",
52
+ ".smartconfig.json",
53
+ "license.md",
47
54
  "readme.md"
48
55
  ],
49
56
  "browserslist": [
@@ -57,5 +64,10 @@
57
64
  "screenshot",
58
65
  "web scraping",
59
66
  "browser automation"
60
- ]
61
- }
67
+ ],
68
+ "scripts": {
69
+ "test": "tstest test/",
70
+ "build": "tsbuild tsfolders",
71
+ "buildDocs": "tsdoc"
72
+ }
73
+ }
package/readme.hints.md CHANGED
@@ -1 +1,25 @@
1
-
1
+ # SmartBrowser Hints
2
+
3
+ ## Dependencies (as of 2026-08-05)
4
+ - `@push.rocks/smartpdf` v5.x uses SmartPuppeteer 2.1/Puppeteer 25 browser types. `SmartPdf` remains lazy and starts only for PDF methods.
5
+ - `@push.rocks/smartpuppeteer` v2.1 owns `LiveBrowserSession` and the canonical transport-neutral live browser contracts.
6
+ - Tests import `@git.zone/tstest/tapbundle`; browser tests use the `.chromium.ts` suffix.
7
+ - The Node.js entry requires Node.js 22.12 or newer. This repository uses pnpm 11.20 for development and release tooling.
8
+ - Puppeteer `page.screenshot({ encoding: 'binary' })` returns `Uint8Array`, not `Buffer` - wrap with `Buffer.from()`
9
+
10
+ ## Build
11
+ - `pnpm run build` uses `tsbuild tsfolders` and emits both `dist_ts` and `dist_ts_web`.
12
+ - `@push.rocks/smartbrowser/web` must remain runtime-isolated from Puppeteer, SmartPDF, Buffer, and Node.js built-ins. Only type imports from SmartPuppeteer are allowed.
13
+ - `pnpm test` runs Node and Chromium files through tstest 4.
14
+
15
+ ## Canvas Renderer Invariants
16
+ - The client facade is transport-neutral. Authentication, authorization, binary wire encoding, session ownership, and egress policy belong to the consuming adapter.
17
+ - Input always carries the identity of the actually displayed frame, never merely the newest state event.
18
+ - Cached state may lag a new frame generation. A state identity ahead of the displayed frame invalidates it; same-identity metadata updates do not.
19
+ - One frame may decode while only the newest subsequent frame waits. The renderer makes at most one acknowledgement request for each drawn, stale, superseded, failed, or shutdown-retired frame; failures and capacity exhaustion are reported and stop the renderer.
20
+ - Renderer starts and explicit stops are serialized by run epoch. A renderer can restart after an explicit stop. Acknowledgement failures, input-release failures, capacity exhaustion, and client/decode timeouts terminally stop the instance because underlying work is not cancellable through the client interface; create a new renderer and client after those failures.
21
+ - Repeated blur, visibility, and pointer-loss resets coalesce into one bounded reset operation.
22
+ - Pressed input is retained until release succeeds, with one retry for transient release failures. Input remains blocked while a release is unresolved.
23
+ - Resize uses a caller-supplied stable CSS element. Requests are latest-only and serialized; input is released before resizing and remains blocked until a frame meeting the target revision fence is drawn.
24
+ - Intrinsic canvas dimensions come from encoded frame dimensions. Pointer coordinates map to the frame's logical CSS viewport.
25
+ - Pointer and wheel listeners remain on the canvas. Keyboard and composition listeners use `focusTarget`, which defaults to the canvas. Call `insertText()` for text committed by an external IME or dedicated input control.
package/readme.md CHANGED
@@ -1,114 +1,231 @@
1
1
  # @push.rocks/smartbrowser
2
- simplified puppeteer
2
+ A simplified Puppeteer wrapper for easy browser automation, PDF generation, screenshots, and page evaluation.
3
+
4
+ The package also provides an isolated browser-side entry at `@push.rocks/smartbrowser/web`. Its `LiveBrowserCanvasRenderer` displays SmartPuppeteer live-session frames in a canvas and maps local input back to transport-neutral browser commands without bundling Puppeteer or Node.js code into the web application.
5
+
6
+ ## Issue Reporting and Security
7
+
8
+ For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
3
9
 
4
10
  ## Install
5
- To install `@push.rocks/smartbrowser`, use the following npm command:
11
+
12
+ Install the package with pnpm:
6
13
 
7
14
  ```bash
8
- npm install @push.rocks/smartbrowser --save
15
+ pnpm add @push.rocks/smartbrowser
9
16
  ```
10
17
 
11
- This will add `@push.rocks/smartbrowser` to your project's dependencies.
18
+ The Node.js entry requires Node.js 22.12 or newer and a Chromium-compatible browser. It uses SmartPuppeteer 2.1, Puppeteer 25, and SmartPDF 5. SmartPuppeteer detects common local, CI, and container environments and configures Chromium accordingly.
12
19
 
13
20
  ## Usage
14
21
 
15
- `@push.rocks/smartbrowser` simplifies interactions with Puppeteer for tasks like generating PDFs or capturing screenshots from webpages. Below are examples illustrating how you can use `@push.rocks/smartbrowser` in your projects.
22
+ `@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
23
 
17
24
  ### Getting Started
18
25
 
19
- First, import `SmartBrowser` from `@push.rocks/smartbrowser`:
26
+ Import and initialize a `SmartBrowser` instance:
20
27
 
21
28
  ```typescript
22
29
  import { SmartBrowser } from '@push.rocks/smartbrowser';
23
- ```
24
-
25
- Then, initialize and start the `SmartBrowser` instance:
26
30
 
27
- ```typescript
28
31
  const smartBrowser = new SmartBrowser();
29
32
  await smartBrowser.start();
30
33
  ```
31
34
 
32
35
  ### Generating a PDF from a Webpage
33
36
 
34
- You can generate a PDF from any webpage URL. This can be particularly useful for generating reports, invoices, or snapshot captures of web content.
37
+ Generate a full-page PDF from any URL. The result includes a `Buffer` with the PDF contents:
35
38
 
36
39
  ```typescript
37
- // Generate a PDF from a page
38
40
  const pdfResult = await smartBrowser.pdfFromPage('https://example.com');
39
- console.log(pdfResult.buffer); // This holds the PDF file's buffer
41
+ console.log(pdfResult.buffer); // PDF file buffer
42
+ console.log(pdfResult.name); // Generated name identifier
40
43
  ```
41
44
 
45
+ 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.
46
+
42
47
  ### Capturing a Screenshot of a Webpage
43
48
 
44
- Similarly, you can capture a screenshot of a webpage by passing the URL. This is useful for capturing the current state of a web application, for audits, or for keeping visual records.
49
+ Capture a PNG screenshot of any webpage:
45
50
 
46
51
  ```typescript
47
- // Capture a screenshot from a page
48
52
  const screenshotResult = await smartBrowser.screenshotFromPage('https://example.com');
49
- console.log(screenshotResult.buffer); // This is the screenshot's buffer
53
+ console.log(screenshotResult.buffer); // Screenshot buffer (PNG)
54
+ console.log(screenshotResult.name); // Short unique identifier
55
+ console.log(screenshotResult.id); // Identifier with extension
50
56
  ```
51
57
 
52
58
  ### Evaluating JavaScript on a Webpage
53
59
 
54
- `SmartBrowser` also allows you to evaluate JavaScript on the webpage. This can be useful for scraping data, testing web applications, or automating interactions with webpages.
60
+ Run arbitrary JavaScript inside a page context and retrieve the result:
55
61
 
56
62
  ```typescript
57
- // Evaluate JavaScript on a page
58
- const pageTitle = await smartBrowser.evaluateOnPage('https://example.com', () => {
59
- return document.title; // Gets the title of the page
63
+ const pageTitle = await smartBrowser.evaluateOnPage('https://example.com', async () => {
64
+ return document.title;
60
65
  });
61
- console.log(pageTitle); // Logs the page title to the console
66
+ console.log(pageTitle); // "Example Domain"
67
+ ```
68
+
69
+ The `evaluateOnPage` method supports generic return types:
70
+
71
+ ```typescript
72
+ const metrics = await smartBrowser.evaluateOnPage<{ width: number; height: number }>(
73
+ 'https://example.com',
74
+ async () => {
75
+ return {
76
+ width: window.innerWidth,
77
+ height: window.innerHeight,
78
+ };
79
+ }
80
+ );
81
+ console.log(metrics.width, metrics.height);
62
82
  ```
63
83
 
84
+ Pages are automatically closed after evaluation, even if an error occurs.
85
+
86
+ ### Accessing the Underlying Puppeteer Browser
87
+
88
+ For advanced use cases, you can access the Puppeteer browser instance directly:
89
+
90
+ ```typescript
91
+ const page = await smartBrowser.headlessBrowser.newPage();
92
+ await page.goto('https://example.com');
93
+ // ... custom Puppeteer operations
94
+ await page.close();
95
+ ```
96
+
97
+ You can also import the `smartpuppeteer` module directly for lower-level browser management:
98
+
99
+ ```typescript
100
+ import { smartpuppeteer } from '@push.rocks/smartbrowser';
101
+
102
+ const browser = await smartpuppeteer.getEnvAwareBrowserInstance();
103
+ ```
104
+
105
+ ## Live Browser Canvas
106
+
107
+ Import the browser-only renderer from `@push.rocks/smartbrowser/web`. The Node.js root entry is intentionally separate and must not be imported into a frontend bundle.
108
+
109
+ The renderer receives a caller-provided `ILiveBrowserCanvasClient`. An application adapter implements that interface using its authenticated transport and keeps the latest `ILiveBrowserState` available through `getState()`. SmartBrowser does not prescribe TypedSocket, WebSocket framing, base64 conversion, authentication, authorization, or session ownership.
110
+
111
+ ```typescript
112
+ import {
113
+ LiveBrowserCanvasRenderer,
114
+ type ILiveBrowserCanvasClient,
115
+ } from '@push.rocks/smartbrowser/web';
116
+
117
+ export async function mountLiveBrowser(client: ILiveBrowserCanvasClient) {
118
+ const viewport = document.querySelector<HTMLElement>('[data-live-browser-viewport]')!;
119
+ const canvas = viewport.querySelector<HTMLCanvasElement>('canvas')!;
120
+
121
+ const renderer = new LiveBrowserCanvasRenderer({
122
+ canvas,
123
+ client,
124
+ // Observe a stable CSS-sized element, not the canvas backing bitmap.
125
+ resizeTarget: viewport,
126
+ onError: (error) => console.error(error.code, error.message),
127
+ });
128
+
129
+ await renderer.start();
130
+ return async () => {
131
+ // Stop the renderer before closing its transport so queued frames can be acknowledged.
132
+ await renderer.stop();
133
+ };
134
+ }
135
+ ```
136
+
137
+ A minimal host keeps CSS sizing independent from the canvas's encoded backing dimensions:
138
+
139
+ ```html
140
+ <div data-live-browser-viewport style="width: 100%; height: 600px; overflow: hidden">
141
+ <canvas style="display: block; width: 100%; height: 100%"></canvas>
142
+ </div>
143
+ ```
144
+
145
+ `ILiveBrowserCanvasClient` exposes the renderer-facing subset of the canonical SmartPuppeteer live-session API:
146
+
147
+ - Cached state and events: `getState()` and `onEvent()`
148
+ - Frame flow control: `acknowledgeFrame()`
149
+ - Viewport synchronization: `setViewport()`
150
+ - Input: `dispatchMouse()`, `dispatchWheel()`, `dispatchKey()`, and `insertText()`
151
+
152
+ The renderer keeps at most one frame decoding and one newest frame queued. It makes one acknowledgement attempt after a frame is drawn, deliberately dropped, found stale, or fails decoding. A failed or timed-out acknowledgement is reported through `onError` and terminally stops the renderer because frame flow control is no longer reliable. Acknowledgement capacity exhaustion also terminally stops the renderer. Input identity always comes from the frame actually displayed, so tab, generation, and viewport changes block stale clicks and keystrokes. Encoded `frame.width` and `frame.height` set the canvas backing bitmap, while pointer coordinates map through the displayed canvas rectangle into the frame's logical CSS viewport.
153
+
154
+ Pointer and wheel input are captured from the canvas. Keyboard and best-effort `compositionend` input are captured from `focusTarget`, which defaults to the canvas and receives focus on pointer down. The renderer temporarily makes an unfocusable focus target focusable and restores its prior `tabindex` on stop. Applications with a dedicated text or IME control can call `renderer.insertText(text)` explicitly.
155
+
156
+ When `resizeTarget` is supplied, resize updates are deduplicated, serialized, and fenced by viewport revision. The target must have stable CSS dimensions that do not depend on `canvas.width` or `canvas.height`; this prevents intrinsic canvas updates from causing resize feedback.
157
+
158
+ `ILiveBrowserCanvasRendererOptions` supports:
159
+
160
+ - `canvas` and `client`: required rendering and transport-adapter dependencies.
161
+ - `focusTarget`: optional keyboard and composition event target; defaults to `canvas`.
162
+ - `resizeTarget`: optional stable CSS-sized element observed for remote viewport updates.
163
+ - `getDeviceScaleFactor`: optional scale provider; defaults to `window.devicePixelRatio` and is useful when the application controls remote scaling explicitly.
164
+ - `operationTimeoutMs`: timeout for client acknowledgements, viewport updates, and input operations; defaults to 10 seconds. A timeout terminally stops the renderer because the underlying adapter operation cannot be cancelled through this interface.
165
+ - `frameDecodeTimeoutMs`: image decode timeout; defaults to `operationTimeoutMs`. A timeout terminally stops the renderer and closes the decoded bitmap if it completes late.
166
+ - `onError`: receives typed `ILiveBrowserCanvasError` values without interrupting renderer cleanup.
167
+ - `onFrameRendered`: called after a current frame has been drawn.
168
+
169
+ The renderer exposes `start()`, `stop()`, `insertText()`, `syncViewport()`, and the `isRunning` getter. `syncViewport()` requests a fresh measurement of the configured `resizeTarget`; it is a no-op when no target is configured or the renderer is stopped. An explicitly stopped renderer can be started again. After an acknowledgement failure, input-release failure, capacity exhaustion, or operation/decode timeout, create a new renderer and client instead; the failed instance rejects future `start()` calls because its non-cancellable underlying work may still affect the old client session. The `/web` entry also exports `ILiveBrowserCanvasClient`, `ILiveBrowserCanvasRendererOptions`, `ILiveBrowserCanvasError`, `TLiveBrowserCanvasErrorCode`, and the canonical SmartPuppeteer live-browser contract types.
170
+
171
+ `LiveBrowserCanvasRenderer` is not a security boundary. The application adapter must authenticate viewers, authorize control, restrict navigation, enforce browser-session ownership, and apply network/egress policy before forwarding commands. The renderer displays webpage viewport pixels only. It does not provide native Chrome UI, audio, extensions, file transfer, clipboard, camera, microphone, or touch emulation.
172
+
64
173
  ### Shutting Down
65
174
 
66
- Once your tasks are complete, it's important to properly shut down the `SmartBrowser` instance to free up resources:
175
+ Always stop the browser instance when done to free resources:
67
176
 
68
177
  ```typescript
69
178
  await smartBrowser.stop();
70
179
  ```
71
180
 
72
- ### Full Example
181
+ This cleanly shuts down the SmartPdf server (if it was initialized) and closes the browser.
73
182
 
74
- Combining the above steps, here's a full example of using `@push.rocks/smartbrowser` to generate a PDF and capture a screenshot of a webpage:
183
+ ### Full Example
75
184
 
76
185
  ```typescript
77
186
  import { SmartBrowser } from '@push.rocks/smartbrowser';
78
187
 
79
- async function generateWebAssets() {
188
+ async function main() {
80
189
  const smartBrowser = new SmartBrowser();
81
190
  await smartBrowser.start();
82
191
 
192
+ // Generate a PDF
83
193
  const pdfResult = await smartBrowser.pdfFromPage('https://example.com');
84
- console.log('PDF Generated:', pdfResult.buffer);
194
+ console.log('PDF size:', pdfResult.buffer.length, 'bytes');
195
+
196
+ // Take a screenshot
197
+ const screenshot = await smartBrowser.screenshotFromPage('https://example.com');
198
+ console.log('Screenshot size:', screenshot.buffer.length, 'bytes');
85
199
 
86
- const screenshotResult = await smartBrowser.screenshotFromPage('https://example.com');
87
- console.log('Screenshot Captured:', screenshotResult.buffer);
200
+ // Evaluate JavaScript
201
+ const title = await smartBrowser.evaluateOnPage('https://example.com', async () => {
202
+ return document.title;
203
+ });
204
+ console.log('Page title:', title);
88
205
 
89
206
  await smartBrowser.stop();
90
207
  }
91
208
 
92
- generateWebAssets();
209
+ main();
93
210
  ```
94
211
 
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
212
  ## License and Legal Information
98
213
 
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.
214
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](license.md) file.
100
215
 
101
216
  **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
217
 
103
218
  ### Trademarks
104
219
 
105
- This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
220
+ This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
221
+
222
+ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
106
223
 
107
224
  ### Company Information
108
225
 
109
- Task Venture Capital GmbH
110
- Registered at District court Bremen HRB 35230 HB, Germany
226
+ Task Venture Capital GmbH<br>
227
+ Registered at District Court Bremen HRB 35230 HB, Germany
111
228
 
112
- For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
229
+ For any legal inquiries or further information, please contact us via email at hello@task.vc.
113
230
 
114
231
  By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartbrowser',
6
- version: '2.0.10',
6
+ version: '3.0.0',
7
7
  description: 'A simplified Puppeteer wrapper for easy automation and testing tasks.'
8
8
  }
package/ts/index.ts CHANGED
@@ -6,8 +6,8 @@ import * as interfaces from './interfaces/index.js';
6
6
  * SmartBrowser
7
7
  */
8
8
  export class SmartBrowser {
9
- public headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser;
10
- public smartpdf: plugins.smartpdf.SmartPdf;
9
+ public headlessBrowser!: plugins.smartpuppeteer.puppeteer.Browser;
10
+ public smartpdf: plugins.smartpdf.SmartPdf | null = null;
11
11
 
12
12
  /**
13
13
  * start the SmartBrowser instance
@@ -20,11 +20,12 @@ export class SmartBrowser {
20
20
  /**
21
21
  * ensure SmartPdf is initialized (lazy)
22
22
  */
23
- private async ensureSmartPdf() {
23
+ private async ensureSmartPdf(): Promise<plugins.smartpdf.SmartPdf> {
24
24
  if (!this.smartpdf) {
25
25
  this.smartpdf = new plugins.smartpdf.SmartPdf();
26
26
  await this.smartpdf.start(this.headlessBrowser);
27
27
  }
28
+ return this.smartpdf;
28
29
  }
29
30
 
30
31
  /**
@@ -43,8 +44,8 @@ export class SmartBrowser {
43
44
  * @param urlArg
44
45
  */
45
46
  public async pdfFromPage(urlArg: string): Promise<plugins.smartpdf.IPdf> {
46
- await this.ensureSmartPdf();
47
- const result = await this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
47
+ const smartpdf = await this.ensureSmartPdf();
48
+ const result = await smartpdf.getFullWebsiteAsSinglePdf(urlArg);
48
49
  return result;
49
50
  }
50
51
 
@@ -58,9 +59,10 @@ export class SmartBrowser {
58
59
  await page.goto(urlArg, {
59
60
  waitUntil: 'networkidle2',
60
61
  });
61
- const screenshotBuffer = (await page.screenshot({
62
+ const screenshotResult = await page.screenshot({
62
63
  encoding: 'binary',
63
- })) as Buffer;
64
+ });
65
+ const screenshotBuffer = Buffer.from(screenshotResult);
64
66
  await page.close();
65
67
  return {
66
68
  name: pageId,
@@ -89,4 +91,4 @@ export class SmartBrowser {
89
91
  }
90
92
 
91
93
  import { smartpuppeteer } from './smartbrowser.plugins.js';
92
- export { smartpuppeteer };
94
+ export { smartpuppeteer };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * autocreated commitinfo by @push.rocks/commitinfo
3
+ */
4
+ export const commitinfo = {
5
+ name: '@push.rocks/smartbrowser',
6
+ version: '3.0.0',
7
+ description: 'A simplified Puppeteer wrapper for easy automation and testing tasks.'
8
+ }