Compare commits
No commits in common. "master" and "v1.0.4" have entirely different histories.
@ -1,66 +0,0 @@
|
|||||||
name: Default (not tags)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags-ignore:
|
|
||||||
- '**'
|
|
||||||
|
|
||||||
env:
|
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
|
||||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Install pnpm and npmci
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
|
|
||||||
- name: Run npm prepare
|
|
||||||
run: npmci npm prepare
|
|
||||||
|
|
||||||
- name: Audit production dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --prod
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Audit development dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --dev
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
test:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: security
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Test stable
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm test
|
|
||||||
|
|
||||||
- name: Test build
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm build
|
|
@ -1,124 +0,0 @@
|
|||||||
name: Default (tags)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- '*'
|
|
||||||
|
|
||||||
env:
|
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
|
||||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
continue-on-error: true
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Audit production dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --prod
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Audit development dependencies
|
|
||||||
run: |
|
|
||||||
npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
npmci command pnpm audit --audit-level=high --dev
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
test:
|
|
||||||
if: ${{ always() }}
|
|
||||||
needs: security
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Test stable
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm test
|
|
||||||
|
|
||||||
- name: Test build
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
npmci npm build
|
|
||||||
|
|
||||||
release:
|
|
||||||
needs: test
|
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Release
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm publish
|
|
||||||
|
|
||||||
metadata:
|
|
||||||
needs: test
|
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ${{ env.IMAGE }}
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Prepare
|
|
||||||
run: |
|
|
||||||
pnpm install -g pnpm
|
|
||||||
pnpm install -g @shipzone/npmci
|
|
||||||
npmci npm prepare
|
|
||||||
|
|
||||||
- name: Code quality
|
|
||||||
run: |
|
|
||||||
npmci command npm install -g typescript
|
|
||||||
npmci npm install
|
|
||||||
|
|
||||||
- name: Trigger
|
|
||||||
run: npmci trigger
|
|
||||||
|
|
||||||
- name: Build docs and upload artifacts
|
|
||||||
run: |
|
|
||||||
npmci node install stable
|
|
||||||
npmci npm install
|
|
||||||
pnpm install -g @gitzone/tsdoc
|
|
||||||
npmci command tsdoc
|
|
||||||
continue-on-error: true
|
|
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,20 +1,3 @@
|
|||||||
.nogit/
|
|
||||||
|
|
||||||
# artifacts
|
|
||||||
coverage/
|
|
||||||
public/
|
|
||||||
pages/
|
|
||||||
|
|
||||||
# installs
|
|
||||||
node_modules/
|
node_modules/
|
||||||
|
pages/
|
||||||
# caches
|
public/
|
||||||
.yarn/
|
|
||||||
.cache/
|
|
||||||
.rpt2_cache
|
|
||||||
|
|
||||||
# builds
|
|
||||||
dist/
|
|
||||||
dist_*/
|
|
||||||
|
|
||||||
# custom
|
|
||||||
|
71
.gitlab-ci.yml
Normal file
71
.gitlab-ci.yml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# gitzone standard
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- .yarn/
|
||||||
|
key: "$CI_BUILD_STAGE"
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
- release
|
||||||
|
- trigger
|
||||||
|
- pages
|
||||||
|
|
||||||
|
testLEGACY:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test legacy
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
testLTS:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test lts
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
testSTABLE:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test stable
|
||||||
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
script:
|
||||||
|
- npmci publish
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
stage: trigger
|
||||||
|
script:
|
||||||
|
- npmci trigger
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
|
||||||
|
pages:
|
||||||
|
image: hosttoday/ht-docker-node:npmci
|
||||||
|
stage: pages
|
||||||
|
script:
|
||||||
|
- npmci command yarn global add npmpage
|
||||||
|
- npmci command npmpage --publish gitlab
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 week
|
||||||
|
paths:
|
||||||
|
- public
|
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"command": "npm test",
|
|
||||||
"name": "Run npm test",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "node-terminal"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"json.schemas": [
|
|
||||||
{
|
|
||||||
"fileMatch": ["/npmextra.json"],
|
|
||||||
"schema": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"npmci": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for npmci"
|
|
||||||
},
|
|
||||||
"gitzone": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "settings for gitzone",
|
|
||||||
"properties": {
|
|
||||||
"projectType": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
29
README.md
Normal file
29
README.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# smartbrowser
|
||||||
|
wraps browser-sync
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
[](https://www.npmjs.com/package/smartbrowser)
|
||||||
|
[](https://GitLab.com/pushrocks/smartbrowser)
|
||||||
|
[](https://github.com/pushrocks/smartbrowser)
|
||||||
|
[](https://pushrocks.gitlab.io/smartbrowser/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://GitLab.com/pushrocks/smartbrowser/commits/master)
|
||||||
|
[](https://GitLab.com/pushrocks/smartbrowser/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/smartbrowser)
|
||||||
|
[](https://david-dm.org/pushrocks/smartbrowser)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartbrowser/master/dependencies/npm)
|
||||||
|
[](https://www.bithound.io/github/pushrocks/smartbrowser)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://push.rocks)
|
64
changelog.md
64
changelog.md
@ -1,64 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
## 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)
|
|
||||||
Update dependencies to latest versions.
|
|
||||||
|
|
||||||
- Updated @push.rocks/smartpdf dependency to version ^3.1.8
|
|
||||||
- Updated @push.rocks/smartunique dependency to version ^3.0.9
|
|
||||||
- Updated devDependencies to the latest versions
|
|
||||||
|
|
||||||
## 2024-05-29 - 2.0.6 - Project Maintenance
|
|
||||||
Minor project maintenance updates.
|
|
||||||
|
|
||||||
- Updated project description
|
|
||||||
- Revised tsconfig settings
|
|
||||||
- Made repeated updates to npmextra.json focusing on 'githost' configuration
|
|
||||||
|
|
||||||
## 2023-07-11 - 2.0.5 - Organizational Updates
|
|
||||||
Switch to new organizational scheme and internal updates.
|
|
||||||
|
|
||||||
- Transitioned project to new organizational scheme
|
|
||||||
|
|
||||||
## 2022-10-26 - 2.0.4 to 2.0.2 - Core Fixes
|
|
||||||
A series of core fixes were applied to ensure better stability and performance.
|
|
||||||
|
|
||||||
## 2022-03-24 - 2.0.1 to 2.0.0 - Core Improvements
|
|
||||||
Significant updates made to the core functionality.
|
|
||||||
|
|
||||||
- Updated core components to enhance performance and reliability
|
|
||||||
|
|
||||||
## 2021-11-07 - 1.0.22 to 1.0.21 - Core Fixes
|
|
||||||
Minor fixes to core components for improved stability.
|
|
||||||
|
|
||||||
## 2021-04-29 - 1.0.20 to 1.0.18 - Core Fixes
|
|
||||||
Routine updates and fixes for core stability.
|
|
||||||
|
|
||||||
## 2020-06-01 - 1.0.16 to 1.0.14 - Bug Fixes
|
|
||||||
Multiple bug fixes and enhancements to the core.
|
|
||||||
|
|
||||||
## 2019-06-04 - 1.0.13 to 1.0.11 - Bug Fixes
|
|
||||||
Addressed several core issues to improve functionality.
|
|
||||||
|
|
||||||
## 2019-05-29 - 1.0.10 to 1.0.6 - Core Updates
|
|
||||||
Numerous updates and fixes were applied to core functionalities.
|
|
||||||
|
|
||||||
## 2017-04-09 - 1.0.5 to 1.0.3 - Feature Enhancements
|
|
||||||
Introduced new features and enhancements.
|
|
||||||
|
|
||||||
- Added .reload() method
|
|
||||||
- Included npmextra.json for better configuration management
|
|
||||||
|
|
||||||
## 2016-09-20 - 1.0.1 to 1.0.0 - Initial Release and Improvements
|
|
||||||
Launched the project with several improvements and setup configurations.
|
|
||||||
|
|
||||||
- Initial project setup and configuration
|
|
||||||
- Enhanced README for better documentation
|
|
||||||
- Integrated GitLab CI for continuous integration
|
|
||||||
|
|
31
dist/index.d.ts
vendored
Normal file
31
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/// <reference types="browser-sync" />
|
||||||
|
import * as plugins from './smartbrowser.plugins';
|
||||||
|
/**
|
||||||
|
* the options interface of a Smartbrowser instance
|
||||||
|
*/
|
||||||
|
export interface ISmartbrowserOptions {
|
||||||
|
webroot: string;
|
||||||
|
watchFiles: string[];
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Type of status that a bsInstance can have
|
||||||
|
*/
|
||||||
|
export declare type bsStatus = 'idle' | 'starting' | 'running';
|
||||||
|
/**
|
||||||
|
* class smartbrowser controls a browser-sync instance for you
|
||||||
|
*/
|
||||||
|
export declare class Smartbrowser {
|
||||||
|
bsInstance: plugins.browserSync.BrowserSyncInstance;
|
||||||
|
bsConfig: plugins.browserSync.Options;
|
||||||
|
bsStatus: bsStatus;
|
||||||
|
bsStarted: Promise<void>;
|
||||||
|
constructor(optionsArg: ISmartbrowserOptions);
|
||||||
|
/**
|
||||||
|
* starts the server and returns the browserSync instance in a resolved Promise
|
||||||
|
*/
|
||||||
|
start(): Promise<plugins.browserSync.BrowserSyncInstance>;
|
||||||
|
/**
|
||||||
|
* stops the smartbrowser instance
|
||||||
|
*/
|
||||||
|
stop(): Promise<void>;
|
||||||
|
}
|
49
dist/index.js
vendored
Normal file
49
dist/index.js
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const plugins = require("./smartbrowser.plugins");
|
||||||
|
/**
|
||||||
|
* class smartbrowser controls a browser-sync instance for you
|
||||||
|
*/
|
||||||
|
class Smartbrowser {
|
||||||
|
constructor(optionsArg) {
|
||||||
|
this.bsInstance = plugins.browserSync.create();
|
||||||
|
this.bsConfig = {
|
||||||
|
server: {}
|
||||||
|
};
|
||||||
|
this.bsStatus = 'idle';
|
||||||
|
this.bsConfig.server.baseDir = optionsArg.webroot;
|
||||||
|
this.bsConfig.files = optionsArg.watchFiles;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* starts the server and returns the browserSync instance in a resolved Promise
|
||||||
|
*/
|
||||||
|
start() {
|
||||||
|
let done = plugins.smartq.defer();
|
||||||
|
if (this.bsStatus === 'idle') {
|
||||||
|
this.bsStatus = 'starting';
|
||||||
|
let localDone = plugins.smartq.defer();
|
||||||
|
this.bsStarted = localDone.promise;
|
||||||
|
this.bsInstance.init(this.bsConfig, () => {
|
||||||
|
this.bsStatus = 'running';
|
||||||
|
localDone.resolve();
|
||||||
|
done.resolve(this.bsInstance);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.bsStarted.then(() => { done.resolve(this.bsInstance); });
|
||||||
|
}
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* stops the smartbrowser instance
|
||||||
|
*/
|
||||||
|
stop() {
|
||||||
|
let done = plugins.smartq.defer();
|
||||||
|
this.bsInstance.exit();
|
||||||
|
this.bsStatus = 'idle';
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.Smartbrowser = Smartbrowser;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGtEQUFpRDtBQWdCakQ7O0dBRUc7QUFDSDtJQU9FLFlBQWEsVUFBZ0M7UUFON0MsZUFBVSxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsTUFBTSxFQUFFLENBQUE7UUFDekMsYUFBUSxHQUFnQztZQUN0QyxNQUFNLEVBQUUsRUFBRTtTQUNYLENBQUE7UUFDRCxhQUFRLEdBQWEsTUFBTSxDQUFBO1FBR3pCLElBQUksQ0FBQyxRQUFRLENBQUMsTUFBTSxDQUFDLE9BQU8sR0FBRyxVQUFVLENBQUMsT0FBTyxDQUFBO1FBQ2pELElBQUksQ0FBQyxRQUFRLENBQUMsS0FBSyxHQUFHLFVBQVUsQ0FBQyxVQUFVLENBQUE7SUFDN0MsQ0FBQztJQUVEOztPQUVHO0lBQ0gsS0FBSztRQUNILElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUEyQyxDQUFBO1FBQzFFLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxRQUFRLEtBQUssTUFBTSxDQUFDLENBQUMsQ0FBQztZQUM3QixJQUFJLENBQUMsUUFBUSxHQUFHLFVBQVUsQ0FBQTtZQUMxQixJQUFJLFNBQVMsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBUSxDQUFBO1lBQzVDLElBQUksQ0FBQyxTQUFTLEdBQUcsU0FBUyxDQUFDLE9BQU8sQ0FBQTtZQUNsQyxJQUFJLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsUUFBUSxFQUFFO2dCQUNsQyxJQUFJLENBQUMsUUFBUSxHQUFHLFNBQVMsQ0FBQTtnQkFDekIsU0FBUyxDQUFDLE9BQU8sRUFBRSxDQUFBO2dCQUNuQixJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQTtZQUMvQixDQUFDLENBQUMsQ0FBQTtRQUNKLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLFFBQVEsSUFBSSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUEsQ0FBQyxDQUFDLENBQUMsQ0FBQTtRQUM5RCxDQUFDO1FBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDckIsQ0FBQztJQUVEOztPQUVHO0lBQ0gsSUFBSTtRQUNGLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUFRLENBQUE7UUFDdkMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxJQUFJLEVBQUUsQ0FBQTtRQUN0QixJQUFJLENBQUMsUUFBUSxHQUFHLE1BQU0sQ0FBQTtRQUN0QixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7UUFDZCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUNyQixDQUFDO0NBQ0Y7QUExQ0Qsb0NBMENDIn0=
|
3
dist/smartbrowser.plugins.d.ts
vendored
Normal file
3
dist/smartbrowser.plugins.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import 'typings-global';
|
||||||
|
export import browserSync = require('browser-sync');
|
||||||
|
export import smartq = require('smartq');
|
6
dist/smartbrowser.plugins.js
vendored
Normal file
6
dist/smartbrowser.plugins.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
require("typings-global");
|
||||||
|
exports.browserSync = require("browser-sync");
|
||||||
|
exports.smartq = require("smartq");
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRicm93c2VyLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGJyb3dzZXIucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDBCQUF1QjtBQUN2Qiw4Q0FBbUQ7QUFDbkQsbUNBQXdDIn0=
|
@ -1,28 +1,7 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmAccessLevel": "public"
|
"globalNpmTools": [
|
||||||
},
|
"npmts"
|
||||||
"gitzone": {
|
|
||||||
"projectType": "npm",
|
|
||||||
"module": {
|
|
||||||
"githost": "code.foss.global",
|
|
||||||
"gitscope": "push.rocks",
|
|
||||||
"gitrepo": "smartbrowser",
|
|
||||||
"description": "A simplified Puppeteer wrapper for easy automation and testing tasks.",
|
|
||||||
"npmPackagename": "@push.rocks/smartbrowser",
|
|
||||||
"license": "MIT",
|
|
||||||
"keywords": [
|
|
||||||
"puppeteer",
|
|
||||||
"automation",
|
|
||||||
"testing",
|
|
||||||
"pdf generation",
|
|
||||||
"screenshot",
|
|
||||||
"web scraping",
|
|
||||||
"browser automation"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
}
|
61
package.json
61
package.json
@ -1,61 +1,30 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartbrowser",
|
"name": "smartbrowser",
|
||||||
"version": "2.0.8",
|
"version": "1.0.4",
|
||||||
"description": "A simplified Puppeteer wrapper for easy automation and testing tasks.",
|
"description": "wraps browser-sync",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(npmts)"
|
||||||
"build": "(tsbuild --web --allowimplicitany)",
|
|
||||||
"buildDocs": "tsdoc"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://code.foss.global/push.rocks/smartbrowser.git"
|
"url": "git+ssh://git@gitlab.com/pushrocks/smartbrowser.git"
|
||||||
},
|
},
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/smartbrowser/issues"
|
"url": "https://gitlab.com/pushrocks/smartbrowser/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/smartbrowser",
|
"homepage": "https://gitlab.com/pushrocks/smartbrowser#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/smartdelay": "^3.0.5",
|
"@types/browser-sync": "0.0.34",
|
||||||
"@push.rocks/smartpdf": "^3.1.8",
|
"browser-sync": "^2.18.8",
|
||||||
"@push.rocks/smartpuppeteer": "^2.0.0",
|
"smartq": "^1.1.1",
|
||||||
"@push.rocks/smartunique": "^3.0.9"
|
"typings-global": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.2.0",
|
"smartdelay": "^1.0.1",
|
||||||
"@git.zone/tsrun": "^1.3.3",
|
"tapbundle": "^1.0.5"
|
||||||
"@git.zone/tstest": "^1.0.90",
|
}
|
||||||
"@push.rocks/tapbundle": "^5.5.4",
|
|
||||||
"@types/node": "^22.10.4"
|
|
||||||
},
|
|
||||||
"private": false,
|
|
||||||
"files": [
|
|
||||||
"ts/**/*",
|
|
||||||
"ts_web/**/*",
|
|
||||||
"dist/**/*",
|
|
||||||
"dist_*/**/*",
|
|
||||||
"dist_ts/**/*",
|
|
||||||
"dist_ts_web/**/*",
|
|
||||||
"assets/**/*",
|
|
||||||
"cli.js",
|
|
||||||
"npmextra.json",
|
|
||||||
"readme.md"
|
|
||||||
],
|
|
||||||
"browserslist": [
|
|
||||||
"last 1 chrome versions"
|
|
||||||
],
|
|
||||||
"keywords": [
|
|
||||||
"puppeteer",
|
|
||||||
"automation",
|
|
||||||
"testing",
|
|
||||||
"pdf generation",
|
|
||||||
"screenshot",
|
|
||||||
"web scraping",
|
|
||||||
"browser automation"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
9722
pnpm-lock.yaml
generated
9722
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
|||||||
|
|
114
readme.md
114
readme.md
@ -1,114 +0,0 @@
|
|||||||
# @push.rocks/smartbrowser
|
|
||||||
simplified puppeteer
|
|
||||||
|
|
||||||
## Install
|
|
||||||
To install `@push.rocks/smartbrowser`, use the following npm command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
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`:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { SmartBrowser } from '@push.rocks/smartbrowser';
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, initialize and start the `SmartBrowser` instance:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
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.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 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:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
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:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
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.
|
|
||||||
|
|
||||||
## 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.
|
|
6
test/assets/index.html
Normal file
6
test/assets/index.html
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<head>
|
||||||
|
<title>Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Test
|
||||||
|
</body>
|
33
test/test.js
Normal file
33
test/test.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
"use strict";
|
||||||
|
require("typings-test");
|
||||||
|
const should = require("should");
|
||||||
|
const smartbrowser = require("../dist/index");
|
||||||
|
let testSmartBrowser;
|
||||||
|
describe('smartbrowser', () => {
|
||||||
|
it('should instanstiate a new browser ', function () {
|
||||||
|
testSmartBrowser = new smartbrowser.Smartbrowser({
|
||||||
|
webroot: './test/assets/',
|
||||||
|
watchFiles: ['./test/assets/']
|
||||||
|
});
|
||||||
|
should(testSmartBrowser).be.instanceof(smartbrowser.Smartbrowser);
|
||||||
|
});
|
||||||
|
it('should start the browser ', function (done) {
|
||||||
|
testSmartBrowser.start().then((bsInstance) => {
|
||||||
|
done();
|
||||||
|
}).catch((err) => { console.log(err); });
|
||||||
|
});
|
||||||
|
it('should stop the browser ', function (done) {
|
||||||
|
this.timeout(10000);
|
||||||
|
setTimeout(() => {
|
||||||
|
testSmartBrowser.stop().then(() => {
|
||||||
|
done();
|
||||||
|
}).catch((err) => { console.log(err); });
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
it('should exit correctly', function () {
|
||||||
|
setTimeout(() => {
|
||||||
|
process.exit(0);
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsOENBQTZDO0FBRTdDLElBQUksZ0JBQTJDLENBQUE7QUFFL0MsUUFBUSxDQUFDLGNBQWMsRUFBRTtJQUNyQixFQUFFLENBQUMsb0NBQW9DLEVBQUU7UUFDckMsZ0JBQWdCLEdBQUcsSUFBSSxZQUFZLENBQUMsWUFBWSxDQUFDO1lBQzdDLE9BQU8sRUFBRSxnQkFBZ0I7WUFDekIsVUFBVSxFQUFFLENBQUMsZ0JBQWdCLENBQUM7U0FDakMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLGdCQUFnQixDQUFDLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxZQUFZLENBQUMsWUFBWSxDQUFDLENBQUE7SUFDckUsQ0FBQyxDQUFDLENBQUE7SUFDRixFQUFFLENBQUMsMkJBQTJCLEVBQUUsVUFBVSxJQUFJO1FBQzFDLGdCQUFnQixDQUFDLEtBQUssRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDLFVBQVU7WUFDckMsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO0lBQzNDLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLDBCQUEwQixFQUFFLFVBQVUsSUFBSTtRQUN6QyxJQUFJLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLFVBQVUsQ0FBQztZQUNQLGdCQUFnQixDQUFDLElBQUksRUFBRSxDQUFDLElBQUksQ0FBQztnQkFDekIsSUFBSSxFQUFFLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxHQUFHLE9BQU8sT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQzNDLENBQUMsRUFBRSxJQUFJLENBQUMsQ0FBQTtJQUNaLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLHVCQUF1QixFQUFDO1FBQ3ZCLFVBQVUsQ0FBQztZQUNQLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDbkIsQ0FBQyxFQUFDLElBQUksQ0FBQyxDQUFBO0lBQ1gsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
51
test/test.ts
51
test/test.ts
@ -1,36 +1,29 @@
|
|||||||
import { tap, expect, expectAsync } from '@push.rocks/tapbundle';
|
import { tap, expect } from 'tapbundle'
|
||||||
|
import * as smartdelay from 'smartdelay'
|
||||||
|
|
||||||
|
import * as smartbrowser from '../dist/index'
|
||||||
|
let testSmartBrowser: smartbrowser.Smartbrowser
|
||||||
|
|
||||||
import * as smartbrowser from '../ts/index.js';
|
|
||||||
let testSmartBrowser: smartbrowser.SmartBrowser;
|
|
||||||
|
|
||||||
tap.test('should instanstiate a new browser ', async () => {
|
tap.test('should instanstiate a new browser ', async () => {
|
||||||
testSmartBrowser = new smartbrowser.SmartBrowser();
|
testSmartBrowser = new smartbrowser.Smartbrowser({
|
||||||
return expect(testSmartBrowser).toBeInstanceOf(smartbrowser.SmartBrowser);
|
webroot: './test/assets/',
|
||||||
});
|
watchFiles: [ './test/assets/' ]
|
||||||
|
})
|
||||||
|
return expect(testSmartBrowser).to.be.instanceof(smartbrowser.Smartbrowser)
|
||||||
|
}).catch(tap.threw)
|
||||||
|
|
||||||
tap.test('should start the browser ', async () => {
|
tap.test('should start the browser ', async () => {
|
||||||
await testSmartBrowser.start();
|
return await expect(testSmartBrowser.start()).to.eventually.be.fulfilled
|
||||||
});
|
}).catch(tap.threw)
|
||||||
|
|
||||||
tap.test('should create a PDF from a page', async (tools) => {
|
|
||||||
const result = await testSmartBrowser.pdfFromPage('https://lossless.com');
|
|
||||||
expect(result.buffer).toBeInstanceOf(Buffer);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should produce a valid screenshot', async (tools) => {
|
|
||||||
const result = await testSmartBrowser.screenshotFromPage('https://lossless.com');
|
|
||||||
expect(result.buffer).toBeInstanceOf(Buffer);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should evalute something in the browser', async () => {
|
|
||||||
const result = await testSmartBrowser.evaluateOnPage('https://lossless.com', async () => {
|
|
||||||
return window.location.toString();
|
|
||||||
});
|
|
||||||
console.log(result);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should stop the browser ', async () => {
|
tap.test('should stop the browser ', async () => {
|
||||||
await testSmartBrowser.stop();
|
return await smartdelay.delayFor(2000).then(() => {
|
||||||
});
|
return expect(testSmartBrowser.stop()).to.eventually.be.fulfilled
|
||||||
|
})
|
||||||
tap.start();
|
})
|
||||||
|
tap.test('should exit correctly', async () => {
|
||||||
|
smartdelay.delayFor(2000).then(() => {
|
||||||
|
process.exit(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
/**
|
|
||||||
* autocreated commitinfo by @push.rocks/commitinfo
|
|
||||||
*/
|
|
||||||
export const commitinfo = {
|
|
||||||
name: '@push.rocks/smartbrowser',
|
|
||||||
version: '2.0.8',
|
|
||||||
description: 'A simplified Puppeteer wrapper for easy automation and testing tasks.'
|
|
||||||
}
|
|
102
ts/index.ts
102
ts/index.ts
@ -1,76 +1,62 @@
|
|||||||
import * as plugins from './smartbrowser.plugins.js';
|
import * as plugins from './smartbrowser.plugins'
|
||||||
|
|
||||||
import * as interfaces from './interfaces/index.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmartBrowser
|
* the options interface of a Smartbrowser instance
|
||||||
*/
|
*/
|
||||||
export class SmartBrowser {
|
export interface ISmartbrowserOptions {
|
||||||
public headlessBrowser: plugins.smartpuppeteer.puppeteer.Browser;
|
webroot: string
|
||||||
public smartpdf: plugins.smartpdf.SmartPdf;
|
watchFiles: string[]
|
||||||
|
|
||||||
/**
|
|
||||||
* start the SmartBrowser instance
|
|
||||||
*/
|
|
||||||
public async start() {
|
|
||||||
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
|
|
||||||
this.smartpdf = new plugins.smartpdf.SmartPdf();
|
|
||||||
await this.smartpdf.start(this.headlessBrowser);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stop the SmartBrowser instance
|
* Type of status that a bsInstance can have
|
||||||
*/
|
*/
|
||||||
public async stop() {
|
export type bsStatus = 'idle' | 'starting' | 'running'
|
||||||
await this.headlessBrowser.close();
|
|
||||||
await this.smartpdf.stop();
|
/**
|
||||||
|
* class smartbrowser controls a browser-sync instance for you
|
||||||
|
*/
|
||||||
|
export class Smartbrowser {
|
||||||
|
bsInstance = plugins.browserSync.create()
|
||||||
|
bsConfig: plugins.browserSync.Options = {
|
||||||
|
server: {}
|
||||||
|
}
|
||||||
|
bsStatus: bsStatus = 'idle'
|
||||||
|
bsStarted: Promise<void>
|
||||||
|
constructor (optionsArg: ISmartbrowserOptions) {
|
||||||
|
this.bsConfig.server.baseDir = optionsArg.webroot
|
||||||
|
this.bsConfig.files = optionsArg.watchFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a pdf from page
|
* starts the server and returns the browserSync instance in a resolved Promise
|
||||||
* @param urlArg
|
|
||||||
*/
|
*/
|
||||||
public async pdfFromPage(urlArg: string): Promise<plugins.smartpdf.IPdf> {
|
start (): Promise<plugins.browserSync.BrowserSyncInstance> {
|
||||||
const result = await this.smartpdf.getFullWebsiteAsSinglePdf(urlArg);
|
let done = plugins.smartq.defer<plugins.browserSync.BrowserSyncInstance>()
|
||||||
return result;
|
if (this.bsStatus === 'idle') {
|
||||||
|
this.bsStatus = 'starting'
|
||||||
|
let localDone = plugins.smartq.defer<void>()
|
||||||
|
this.bsStarted = localDone.promise
|
||||||
|
this.bsInstance.init(this.bsConfig, () => {
|
||||||
|
this.bsStatus = 'running'
|
||||||
|
localDone.resolve()
|
||||||
|
done.resolve(this.bsInstance)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.bsStarted.then(() => { done.resolve(this.bsInstance) })
|
||||||
|
}
|
||||||
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* make a screenshot from a page
|
* stops the smartbrowser instance
|
||||||
* @param urlArg
|
|
||||||
*/
|
*/
|
||||||
public async screenshotFromPage(urlArg: string): Promise<interfaces.IScreenShotResult> {
|
stop (): Promise<void> {
|
||||||
const pageId = plugins.smartunique.shortId();
|
let done = plugins.smartq.defer<void>()
|
||||||
const page = await this.headlessBrowser.newPage();
|
this.bsInstance.exit()
|
||||||
await page.goto(urlArg, {
|
this.bsStatus = 'idle'
|
||||||
waitUntil: 'networkidle2',
|
done.resolve()
|
||||||
});
|
return done.promise
|
||||||
const screenshotBuffer = (await page.screenshot({
|
|
||||||
encoding: 'binary',
|
|
||||||
})) as Buffer;
|
|
||||||
await page.close();
|
|
||||||
return {
|
|
||||||
name: pageId,
|
|
||||||
id: `${pageId}.js`,
|
|
||||||
buffer: screenshotBuffer,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* evalutes an expression on a page
|
|
||||||
* @param urlArg
|
|
||||||
* @param funcArg
|
|
||||||
*/
|
|
||||||
public async evaluateOnPage<T>(urlArg: string, funcArg: () => Promise<T>) {
|
|
||||||
const page = await this.headlessBrowser.newPage();
|
|
||||||
await page.goto(urlArg, {
|
|
||||||
waitUntil: 'networkidle2',
|
|
||||||
});
|
|
||||||
const result = await page.evaluate(funcArg);
|
|
||||||
await page.close();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
import { smartpuppeteer } from './smartbrowser.plugins.js';
|
|
||||||
export { smartpuppeteer };
|
|
@ -1 +0,0 @@
|
|||||||
export * from './interfaces.screenshotresult.js';
|
|
@ -1,5 +0,0 @@
|
|||||||
export interface IScreenShotResult {
|
|
||||||
name: string;
|
|
||||||
id: string;
|
|
||||||
buffer: Buffer;
|
|
||||||
}
|
|
@ -1,8 +1,3 @@
|
|||||||
// pushrocks scope
|
import 'typings-global'
|
||||||
import * as smartpdf from '@push.rocks/smartpdf';
|
export import browserSync = require('browser-sync')
|
||||||
import * as smartpuppeteer from '@push.rocks/smartpuppeteer';
|
export import smartq = require('smartq')
|
||||||
import * as smartunique from '@push.rocks/smartunique';
|
|
||||||
|
|
||||||
export { smartpdf, smartpuppeteer, smartunique };
|
|
||||||
|
|
||||||
// third party
|
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"useDefineForClassFields": false,
|
|
||||||
"target": "ES2022",
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"verbatimModuleSyntax": true
|
|
||||||
},
|
|
||||||
"exclude": [
|
|
||||||
"dist_*/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "tslint-config-standard"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user