A simplified Puppeteer wrapper for easy automation and testing tasks.
Go to file
2024-05-29 14:11:51 +02:00
.gitea/workflows fix(core): update 2023-09-11 10:18:45 +02:00
.vscode fix(core): update 2021-11-07 20:42:49 +01:00
test fix(core): update 2023-09-11 10:18:45 +02:00
ts fix(core): update 2023-09-11 10:18:45 +02:00
.gitignore fix(core): update 2020-06-01 20:19:25 +00:00
npmextra.json update tsconfig 2024-04-14 17:21:37 +02:00
package.json update description 2024-05-29 14:11:51 +02:00
pnpm-lock.yaml fix(core): update 2023-09-11 10:18:45 +02:00
readme.hints.md update tsconfig 2024-04-14 17:21:37 +02:00
readme.md update tsconfig 2024-04-14 17:21:37 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:33:53 +02:00

@push.rocks/smartbrowser

simplified puppeteer

Install

To install @push.rocks/smartbrowser, use the following npm command:

npm install @push.rocks/smartbrowser --save

This will add @push.rocks/smartbrowser to your project's dependencies.

Usage

@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.

Getting Started

First, import SmartBrowser from @push.rocks/smartbrowser:

import { SmartBrowser } from '@push.rocks/smartbrowser';

Then, initialize and start the SmartBrowser instance:

const smartBrowser = new SmartBrowser();
await smartBrowser.start();

Generating a PDF from a Webpage

You can generate a PDF from any webpage URL. This can be particularly useful for generating reports, invoices, or snapshot captures of web content.

// Generate a PDF from a page
const pdfResult = await smartBrowser.pdfFromPage('https://example.com');
console.log(pdfResult.buffer); // This holds the PDF file's buffer

Capturing a Screenshot of a Webpage

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.

// Capture a screenshot from a page
const screenshotResult = await smartBrowser.screenshotFromPage('https://example.com');
console.log(screenshotResult.buffer); // This is the screenshot's buffer

Evaluating JavaScript on a Webpage

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.

// Evaluate JavaScript on a page
const pageTitle = await smartBrowser.evaluateOnPage('https://example.com', () => {
  return document.title; // Gets the title of the page
});
console.log(pageTitle); // Logs the page title to the console

Shutting Down

Once your tasks are complete, it's important to properly shut down the SmartBrowser instance to free up resources:

await smartBrowser.stop();

Full Example

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:

import { SmartBrowser } from '@push.rocks/smartbrowser';

async function generateWebAssets() {
  const smartBrowser = new SmartBrowser();
  await smartBrowser.start();

  const pdfResult = await smartBrowser.pdfFromPage('https://example.com');
  console.log('PDF Generated:', pdfResult.buffer);

  const screenshotResult = await smartBrowser.screenshotFromPage('https://example.com');
  console.log('Screenshot Captured:', screenshotResult.buffer);

  await smartBrowser.stop();
}

generateWebAssets();

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.

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 file within this repository.

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.

Trademarks

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.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

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.