Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 25d191a95b | |||
| d5b3e48f8d | |||
| dd6f24551d | |||
| f4d0e9ad87 | |||
| 41aefa7f18 | |||
| c9f42b4c66 | |||
| 0645364ca9 | |||
| 2d3f59cc65 | |||
| 0e9c81b898 | |||
| 64cd7cd75d |
105
.gitlab-ci.yml
105
.gitlab-ci.yml
@@ -1,16 +1,16 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@@ -18,10 +18,11 @@ stages:
|
|||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
@@ -31,89 +32,89 @@ snyk:
|
|||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
testLTS:
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- priv
|
||||||
testSTABLE:
|
|
||||||
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# metadata stage
|
# metadata stage
|
||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- priv
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- lossless
|
||||||
- notpriv
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@@ -121,5 +122,5 @@ pages:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|||||||
762
package-lock.json
generated
762
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
28
package.json
28
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpuppeteer",
|
"name": "@pushrocks/smartpuppeteer",
|
||||||
"version": "1.0.5",
|
"version": "1.0.10",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "simplified access to puppeteer",
|
"description": "simplified access to puppeteer",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@@ -13,23 +13,25 @@
|
|||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.0.13",
|
||||||
"@types/node": "^10.11.7",
|
"@types/node": "^12.12.7",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^5.20.1",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/puppeteer": "^1.12.4",
|
"@pushrocks/smartenv": "^4.0.8",
|
||||||
"puppeteer": "^1.17.0"
|
"@types/puppeteer": "^1.20.2",
|
||||||
|
"puppeteer": "^2.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_web/**/*",
|
||||||
"assets/*",
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
|||||||
13
readme.md
13
readme.md
@@ -18,9 +18,18 @@ simplified access to puppeteer
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
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). :)
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
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). :)
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
[](https://maintainedby.lossless.com)
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
|||||||
import * as smartpuppeteer from '../ts/index';
|
import * as smartpuppeteer from '../ts/index';
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance();
|
const headlessBrowser = await smartpuppeteer.getEnvAwareBrowserInstance({
|
||||||
|
forceNoSandbox: true
|
||||||
|
});
|
||||||
await headlessBrowser.close();
|
await headlessBrowser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
15
ts/index.ts
15
ts/index.ts
@@ -1,14 +1,7 @@
|
|||||||
import puppeteer from 'puppeteer';
|
// module exports
|
||||||
|
|
||||||
export const getEnvAwareBrowserInstance = async (): Promise<puppeteer.Browser> => {
|
export * from './smartpuppeteer.classes.smartpuppeteer';
|
||||||
let chromeArgs: string[] = [];
|
|
||||||
if (process.env.CI) {
|
|
||||||
chromeArgs = chromeArgs.concat(['--no-sandbox', '--disable-setuid-sandbox']);
|
|
||||||
}
|
|
||||||
const headlessBrowser = await puppeteer.launch({
|
|
||||||
args: chromeArgs
|
|
||||||
});
|
|
||||||
return headlessBrowser;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// direct exports
|
||||||
|
import { puppeteer } from './smartpuppeteer.plugins';
|
||||||
export { puppeteer };
|
export { puppeteer };
|
||||||
|
|||||||
50
ts/smartpuppeteer.classes.smartpuppeteer.ts
Normal file
50
ts/smartpuppeteer.classes.smartpuppeteer.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import * as plugins from './smartpuppeteer.plugins';
|
||||||
|
|
||||||
|
export interface IEnvAwareOptions {
|
||||||
|
forceNoSandbox?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getEnvAwareBrowserInstance = async (
|
||||||
|
optionsArg: IEnvAwareOptions = {}
|
||||||
|
): Promise<plugins.puppeteer.Browser> => {
|
||||||
|
const smartenv = new plugins.smartenv.Smartenv();
|
||||||
|
const options: IEnvAwareOptions = {
|
||||||
|
...{
|
||||||
|
forceNoSandbox: false
|
||||||
|
},
|
||||||
|
...optionsArg
|
||||||
|
};
|
||||||
|
|
||||||
|
let chromeArgs: string[] = [];
|
||||||
|
if ((process.env.CI || options.forceNoSandbox) && !smartenv.isWsl) {
|
||||||
|
chromeArgs = chromeArgs.concat([
|
||||||
|
'--no-sandbox',
|
||||||
|
'--disable-setuid-sandbox',
|
||||||
|
// '--disable-dev-shm-usage'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let headlessBrowser: plugins.puppeteer.Browser;
|
||||||
|
if (!smartenv.isWsl) {
|
||||||
|
// lets get the actual instance
|
||||||
|
console.log('launching puppeteer bundled chrome');
|
||||||
|
headlessBrowser = await plugins.puppeteer.launch({
|
||||||
|
args: chromeArgs
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('Detected WSL. Using chromium.');
|
||||||
|
headlessBrowser = await plugins.puppeteer.launch({
|
||||||
|
args: [
|
||||||
|
'--disable-gpu',
|
||||||
|
'--disable-dev-shm-usage',
|
||||||
|
'--disable-setuid-sandbox',
|
||||||
|
'--no-first-run',
|
||||||
|
'--no-sandbox',
|
||||||
|
'--no-zygote',
|
||||||
|
'--single-process'
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return headlessBrowser;
|
||||||
|
};
|
||||||
9
ts/smartpuppeteer.plugins.ts
Normal file
9
ts/smartpuppeteer.plugins.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// @pushrocks scope
|
||||||
|
import * as smartenv from '@pushrocks/smartenv';
|
||||||
|
|
||||||
|
export { smartenv };
|
||||||
|
|
||||||
|
// third party scope
|
||||||
|
import puppeteer from 'puppeteer';
|
||||||
|
|
||||||
|
export { puppeteer };
|
||||||
Reference in New Issue
Block a user