update tsconfig
This commit is contained in:
parent
57776a67b3
commit
229e35c9da
@ -8,14 +8,24 @@
|
||||
"shortDescription": "simplified access to puppeteer",
|
||||
"npmPackagename": "@push.rocks/smartpuppeteer",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
"projectDomain": "push.rocks",
|
||||
"description": "Provides simplified access to Puppeteer for automation and testing purposes.",
|
||||
"keywords": [
|
||||
"puppeteer",
|
||||
"automation",
|
||||
"browser automation",
|
||||
"web scraping",
|
||||
"testing",
|
||||
"headless browsing",
|
||||
"incognito browsing"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdocs": {
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis 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. \n\n**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.\n\n### Trademarks\n\nThis 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.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy 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.\n"
|
||||
}
|
||||
}
|
13
package.json
13
package.json
@ -2,7 +2,7 @@
|
||||
"name": "@push.rocks/smartpuppeteer",
|
||||
"version": "2.0.3",
|
||||
"private": false,
|
||||
"description": "simplified access to puppeteer",
|
||||
"description": "Provides simplified access to Puppeteer for automation and testing purposes.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
@ -39,5 +39,14 @@
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"keywords": [
|
||||
"puppeteer",
|
||||
"automation",
|
||||
"browser automation",
|
||||
"web scraping",
|
||||
"testing",
|
||||
"headless browsing",
|
||||
"incognito browsing"
|
||||
]
|
||||
}
|
||||
}
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
159
readme.md
159
readme.md
@ -1,46 +1,133 @@
|
||||
# @push.rocks/smartpuppeteer
|
||||
simplified access to puppeteer
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartpuppeteer)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartpuppeteer)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartpuppeteer)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpuppeteer/)
|
||||
## Install
|
||||
To install `@push.rocks/smartpuppeteer` in your project, run the following command using npm:
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/pipeline.svg)](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartpuppeteer/badges/master/coverage.svg)](https://lossless.cloud)
|
||||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartpuppeteer)](https://lossless.cloud)
|
||||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartpuppeteer)](https://lossless.cloud)
|
||||
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
||||
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartpuppeteer)](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartpuppeteer)](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartpuppeteer)](https://lossless.cloud)
|
||||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class intellisense.
|
||||
|
||||
```typescript
|
||||
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
|
||||
forceNoSandbox: true, // if you really want no sandbox, you can do this. Otherwise its starting things as necessary
|
||||
});
|
||||
await headlessBrowser.close();
|
||||
```sh
|
||||
npm install @push.rocks/smartpuppeteer --save
|
||||
```
|
||||
|
||||
## Contribution
|
||||
Or using yarn:
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
```sh
|
||||
yarn add @push.rocks/smartpuppeteer
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
## Usage
|
||||
`@push.rocks/smartpuppeteer` simplifies interaction with Puppeteer, providing easier ways to launch Puppeteer instances considering environment constraints, such as running in a CI pipeline or as root, which necessitates certain flags for Chrome.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
Here, we give a comprehensive guide to using `@push.rocks/smartpuppeteer` in various scenarios, using ESM syntax and TypeScript.
|
||||
|
||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||
### Basic Setup
|
||||
Firstly, let’s set up the basic environment for using `@push.rocks/smartpuppeteer`:
|
||||
|
||||
```typescript
|
||||
import { getEnvAwareBrowserInstance, IncognitoBrowser, puppeteer } from '@push.rocks/smartpuppeteer';
|
||||
|
||||
// Usually, you would initialize the browser instance at the start of your script or application logic
|
||||
const initializeBrowser = async () => {
|
||||
const browser = await getEnvAwareBrowserInstance({
|
||||
forceNoSandbox: true, // A flag useful for certain environments; use it with caution
|
||||
});
|
||||
return browser;
|
||||
};
|
||||
```
|
||||
|
||||
### Opening a Page and Navigating
|
||||
After obtaining a browser instance, you commonly want to open a page and navigate to a URL:
|
||||
|
||||
```typescript
|
||||
const openPage = async (browser: puppeteer.Browser) => {
|
||||
const page = await browser.newPage();
|
||||
await page.goto('https://www.example.com');
|
||||
const pageTitle = await page.title();
|
||||
console.log(`Page title: ${pageTitle}`);
|
||||
// Always close the browser after you are done to free resources
|
||||
await browser.close();
|
||||
};
|
||||
|
||||
// Utilize the async function
|
||||
initializeBrowser()
|
||||
.then(openPage)
|
||||
.catch(console.error);
|
||||
```
|
||||
|
||||
### Using Incognito Mode for Isolated Sessions
|
||||
`@push.rocks/smartpuppeteer` offers easy management of incognito sessions, allowing isolated environments within the same browser instance:
|
||||
|
||||
```typescript
|
||||
const useIncognitoBrowser = async () => {
|
||||
const incognitoBrowser = new IncognitoBrowser();
|
||||
await incognitoBrowser.start(); // Initializes a new incognito browser instance
|
||||
const context = await incognitoBrowser.getNewIncognitoContext();
|
||||
const page = await context.newPage();
|
||||
await page.goto('https://www.privacyfocusedsite.com');
|
||||
// Perform actions in the isolated session
|
||||
// Tidy up
|
||||
await incognitoBrowser.stop(); // Stops the incognito browser and closes all its pages and contexts
|
||||
};
|
||||
|
||||
useIncognitoBrowser()
|
||||
.then(() => console.log('Incognito session used successfully'))
|
||||
.catch(console.error);
|
||||
```
|
||||
|
||||
### Advanced Configuration
|
||||
`@push.rocks/smartpuppeteer` allows further customization for launching the Puppeteer browser, such as disabling the sandbox environment (not recommended for production).
|
||||
|
||||
### Handling Browser Events
|
||||
It's important to handle browser events, such as disconnections, which might occur due to various reasons:
|
||||
|
||||
```typescript
|
||||
const browserWithEventHandling = async () => {
|
||||
const browser = await getEnvAwareBrowserInstance();
|
||||
browser.on('disconnected', () => {
|
||||
console.log('Browser disconnected. Handling reconnection...');
|
||||
// Implement reconnection logic here
|
||||
});
|
||||
// Utilize the browser for tasks
|
||||
};
|
||||
|
||||
browserWithEventHandling()
|
||||
.then(() => console.log('Handled browser events successfully'))
|
||||
.catch(console.error);
|
||||
```
|
||||
|
||||
### Rotation of Browsers and Pages
|
||||
In scenarios such as web scraping or automated testing, you might want to rotate between browser instances or pages to manage memory usage or simulate new sessions:
|
||||
|
||||
```typescript
|
||||
const rotateBrowserInstances = async (incognitoBrowser: IncognitoBrowser) => {
|
||||
// Assuming incognitoBrowser is already initialized and started
|
||||
await incognitoBrowser.rotateBrowser(); // Closes the current browser and starts a new instance
|
||||
// Now you have a fresh browser instance
|
||||
};
|
||||
|
||||
// Example usage
|
||||
const incognitoBrowser = new IncognitoBrowser();
|
||||
incognitoBrowser.start()
|
||||
.then(() => rotateBrowserInstances(incognitoBrowser))
|
||||
.catch(console.error);
|
||||
```
|
||||
|
||||
`@push.rocks/smartpuppeteer` with its encapsulated features and simplified API provides an efficient way to harness the power of Puppeteer without getting bogged down by its complexities. Whether you are handling web scraping, automated testing, or any task requiring browser automation, `@push.rocks/smartpuppeteer` streamlines the process, making it more accessible and manageable even for those new to Puppeteer.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
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.
|
||||
|
||||
**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.
|
||||
|
Loading…
Reference in New Issue
Block a user