4 Commits

Author SHA1 Message Date
79d02bf806 v2.0.9
Some checks failed
Default (tags) / security (push) Failing after 0s
Default (tags) / test (push) Failing after 0s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-03-09 16:16:15 +00:00
654cd2619c fix(smartpdf): lazily initialize SmartPdf, stop it only when present, and make evaluateOnPage reliably close pages 2026-03-09 16:16:15 +00:00
efda7c7b01 2.0.8 2025-01-03 00:14:04 +01:00
2110ab7325 fix(core): Ensure consistent browser automation functionality 2025-01-03 00:14:03 +01:00
5 changed files with 291 additions and 283 deletions

View File

@@ -1,5 +1,20 @@
# Changelog # Changelog
## 2026-03-09 - 2.0.9 - fix(smartpdf)
lazily initialize SmartPdf, stop it only when present, and make evaluateOnPage reliably close pages
- Add private ensureSmartPdf() to lazily initialize and start SmartPdf only when PDF methods are called
- Call ensureSmartPdf() in pdfFromPage() before using smartpdf
- Stop SmartPdf in stop() only if it was initialized and clear the reference
- Wrap evaluateOnPage() page operations in try/finally and safely ignore errors from page.close() to avoid resource leaks or uncaught exceptions
## 2025-01-03 - 2.0.8 - fix(core)
Ensure consistent browser automation functionality
- Verified browser initialization and shutdown
- Tested PDF generation from web pages
- Validated screenshot capturing
## 2025-01-02 - 2.0.7 - fix(dependencies) ## 2025-01-02 - 2.0.7 - fix(dependencies)
Update dependencies to latest versions. Update dependencies to latest versions.

View File

@@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/smartbrowser", "name": "@push.rocks/smartbrowser",
"version": "2.0.7", "version": "2.0.9",
"description": "A simplified Puppeteer wrapper for easy automation and testing tasks.", "description": "A simplified Puppeteer wrapper for easy automation and testing tasks.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",

521
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartbrowser', name: '@push.rocks/smartbrowser',
version: '2.0.7', version: '2.0.9',
description: 'A simplified Puppeteer wrapper for easy automation and testing tasks.' description: 'A simplified Puppeteer wrapper for easy automation and testing tasks.'
} }

View File

@@ -14,16 +14,28 @@ export class SmartBrowser {
*/ */
public async start() { public async start() {
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance(); this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
this.smartpdf = new plugins.smartpdf.SmartPdf(); // SmartPdf is lazy-initialized only when PDF methods are called
await this.smartpdf.start(this.headlessBrowser); }
/**
* ensure SmartPdf is initialized (lazy)
*/
private async ensureSmartPdf() {
if (!this.smartpdf) {
this.smartpdf = new plugins.smartpdf.SmartPdf();
await this.smartpdf.start(this.headlessBrowser);
}
} }
/** /**
* stop the SmartBrowser instance * stop the SmartBrowser instance
*/ */
public async stop() { public async stop() {
if (this.smartpdf) {
await this.smartpdf.stop();
this.smartpdf = null;
}
await this.headlessBrowser.close(); await this.headlessBrowser.close();
await this.smartpdf.stop();
} }
/** /**
@@ -31,6 +43,7 @@ export class SmartBrowser {
* @param urlArg * @param urlArg
*/ */
public async pdfFromPage(urlArg: string): Promise<plugins.smartpdf.IPdf> { public async pdfFromPage(urlArg: string): Promise<plugins.smartpdf.IPdf> {
await this.ensureSmartPdf();
const result = await this.smartpdf.getFullWebsiteAsSinglePdf(urlArg); const result = await this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
return result; return result;
} }
@@ -63,12 +76,15 @@ export class SmartBrowser {
*/ */
public async evaluateOnPage<T>(urlArg: string, funcArg: () => Promise<T>) { public async evaluateOnPage<T>(urlArg: string, funcArg: () => Promise<T>) {
const page = await this.headlessBrowser.newPage(); const page = await this.headlessBrowser.newPage();
await page.goto(urlArg, { try {
waitUntil: 'networkidle2', await page.goto(urlArg, {
}); waitUntil: 'networkidle2',
const result = await page.evaluate(funcArg); });
await page.close(); const result = await page.evaluate(funcArg);
return result; return result;
} finally {
try { await page.close(); } catch (e) { /* page may already be closed */ }
}
} }
} }