@oro-dxeco/playwright-aws-lambda 0.9.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
1
- name: Node.js Package
2
- on:
3
- release:
4
- types: [created]
5
- jobs:
6
- publish-npm:
7
- runs-on: ubuntu-latest
8
- steps:
9
- - uses: actions/checkout@v2
10
- - uses: actions/setup-node@v1
11
- with:
12
- node-version: 12
13
- registry-url: https://registry.npmjs.org/
14
- - name: Install dependencies
15
- run: yarn install --frozen-lockfile
16
- - name: Build project
17
- run: yarn run build
18
- - run: npm publish
19
- env:
20
- NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
1
+ name: Node.js Package
2
+ on:
3
+ release:
4
+ types: [created]
5
+ jobs:
6
+ publish-npm:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: actions/setup-node@v1
11
+ with:
12
+ node-version: 12
13
+ registry-url: https://registry.npmjs.org/
14
+ - name: Install dependencies
15
+ run: yarn install --frozen-lockfile
16
+ - name: Build project
17
+ run: yarn run build
18
+ - run: npm publish
19
+ env:
20
+ NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
@@ -1,23 +1,23 @@
1
- name: CI
2
- on:
3
- push:
4
- branches: [ master ]
5
- pull_request:
6
- branches: [ master ]
7
- jobs:
8
- test:
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v2
12
- - name: Use Node.js
13
- uses: actions/setup-node@v1
14
- with:
15
- node-version: 10.x
16
- - name: Install dependencies
17
- run: yarn install --frozen-lockfile
18
- - name: Lint
19
- run: yarn run lint
20
- - name: Build project
21
- run: yarn run build
22
- - name: Test lambda function
23
- run: bash buildbots/test.sh
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [ master ]
5
+ pull_request:
6
+ branches: [ master ]
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Use Node.js
13
+ uses: actions/setup-node@v1
14
+ with:
15
+ node-version: 10.x
16
+ - name: Install dependencies
17
+ run: yarn install --frozen-lockfile
18
+ - name: Lint
19
+ run: yarn run lint
20
+ - name: Build project
21
+ run: yarn run build
22
+ - name: Test lambda function
23
+ run: bash buildbots/test.sh
package/CODEOWNERS CHANGED
@@ -1,2 +1,3 @@
1
- * @jupiterone/integrations-tooling
1
+ * @jupiterone/janus
2
+
2
3
  CODEOWNERS @jupiterone/security
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 Austin Kelleher
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Austin Kelleher
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,67 +1,67 @@
1
- # playwright-aws-lambda
2
-
3
- ![CI](https://github.com/JupiterOne/playwright-aws-lambda/workflows/CI/badge.svg)
4
- [![NPM](https://img.shields.io/npm/v/playwright-aws-lambda)](https://www.npmjs.com/package/playwright-aws-lambda)
5
-
6
- Support for Playwright running on AWS Lambda and Google Cloud Functions.
7
-
8
- **NOTE**: Currently only Chromium is supported.
9
-
10
- ## Install
11
-
12
- ```shell
13
- npm install playwright-core playwright-aws-lambda --save
14
- ```
15
-
16
- ## Usage
17
-
18
- This package works with the `nodejs10.x`, `nodejs12.x` and `nodejs14.x` AWS Lambda runtimes
19
- out of the box.
20
-
21
- ```javascript
22
- const playwright = require('playwright-aws-lambda');
23
-
24
- exports.handler = async (event, context) => {
25
- let browser = null;
26
-
27
- try {
28
- browser = await playwright.launchChromium();
29
- const context = await browser.newContext();
30
-
31
- const page = await context.newPage();
32
- await page.goto(event.url || 'https://example.com');
33
-
34
- console.log('Page title: ', await page.title());
35
- } catch (error) {
36
- throw error;
37
- } finally {
38
- if (browser) {
39
- await browser.close();
40
- }
41
- }
42
- };
43
- ```
44
-
45
- ## API
46
-
47
- | Method / Property | Returns | Description |
48
- | ----------------- | ---------------------------------------- | ------------------------------------- |
49
- | `launchChromium` | `{!Promise<playwright.ChromiumBrowser>}` | Launches the Chromium browser. |
50
- | `loadFont(url)` | `{Promise<void>}` | Downloads and activates a custom font |
51
-
52
- ### Loading additional fonts
53
-
54
- If you need custom font support by e.g. emojicons in your browser, you have to
55
- load it by using the `loadFont(url: string)` function before you launch the
56
- browser.
57
-
58
- ```js
59
- await loadFont(
60
- 'https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf'
61
- );
62
- ```
63
-
64
- ## Thanks / Credits
65
-
66
- This project is based on the work of
67
- [chrome-aws-lambda](https://github.com/alixaxel/chrome-aws-lambda).
1
+ # playwright-aws-lambda
2
+
3
+ ![CI](https://github.com/JupiterOne/playwright-aws-lambda/workflows/CI/badge.svg)
4
+ [![NPM](https://img.shields.io/npm/v/playwright-aws-lambda)](https://www.npmjs.com/package/playwright-aws-lambda)
5
+
6
+ Support for Playwright running on AWS Lambda and Google Cloud Functions.
7
+
8
+ **NOTE**: Currently only Chromium is supported.
9
+
10
+ ## Install
11
+
12
+ ```shell
13
+ npm install playwright-core playwright-aws-lambda --save
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ This package works with the `nodejs10.x`, `nodejs12.x`, `nodejs14.x`, `nodejs16.x` and `nodejs18.x` AWS Lambda runtimes
19
+ out of the box.
20
+
21
+ ```javascript
22
+ const playwright = require('playwright-aws-lambda');
23
+
24
+ exports.handler = async (event, context) => {
25
+ let browser = null;
26
+
27
+ try {
28
+ browser = await playwright.launchChromium();
29
+ const context = await browser.newContext();
30
+
31
+ const page = await context.newPage();
32
+ await page.goto(event.url || 'https://example.com');
33
+
34
+ console.log('Page title: ', await page.title());
35
+ } catch (error) {
36
+ throw error;
37
+ } finally {
38
+ if (browser) {
39
+ await browser.close();
40
+ }
41
+ }
42
+ };
43
+ ```
44
+
45
+ ## API
46
+
47
+ | Method / Property | Returns | Description |
48
+ | ----------------- | ---------------------------------------- | ------------------------------------- |
49
+ | `launchChromium` | `{!Promise<playwright.ChromiumBrowser>}` | Launches the Chromium browser. |
50
+ | `loadFont(url)` | `{Promise<void>}` | Downloads and activates a custom font |
51
+
52
+ ### Loading additional fonts
53
+
54
+ If you need custom font support by e.g. emojicons in your browser, you have to
55
+ load it by using the `loadFont(url: string)` function before you launch the
56
+ browser.
57
+
58
+ ```js
59
+ await loadFont(
60
+ 'https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf'
61
+ );
62
+ ```
63
+
64
+ ## Thanks / Credits
65
+
66
+ This project is based on the work of
67
+ [chrome-aws-lambda](https://github.com/alixaxel/chrome-aws-lambda).
@@ -1,30 +1,30 @@
1
- const playwright = require('../../dist/src/');
2
- const assert = require('assert');
3
-
4
- exports.handler = async (event, context) => {
5
- let browser = null;
6
-
7
- try {
8
- const browser = await playwright.launchChromium();
9
- const context = await browser.newContext();
10
-
11
- const page = await context.newPage();
12
- await page.goto(event.url || 'https://example.com');
13
-
14
- const data = await page.screenshot();
15
- assert(data.length > 0, 'Page screenshot is empty');
16
-
17
- assert((await page.title()) === 'Google', 'Title does not match');
18
-
19
- // Test so it does not crash
20
- await page.setContent('<span id="icon">🎭</span>');
21
-
22
- console.log('inside-lambda: Passed tests');
23
- } catch (error) {
24
- throw error;
25
- } finally {
26
- if (browser !== null) {
27
- await browser.close();
28
- }
29
- }
30
- };
1
+ const playwright = require('../../dist/src/');
2
+ const assert = require('assert');
3
+
4
+ exports.handler = async (event, context) => {
5
+ let browser = null;
6
+
7
+ try {
8
+ const browser = await playwright.launchChromium();
9
+ const context = await browser.newContext();
10
+
11
+ const page = await context.newPage();
12
+ await page.goto(event.url || 'https://example.com');
13
+
14
+ const data = await page.screenshot();
15
+ assert(data.length > 0, 'Page screenshot is empty');
16
+
17
+ assert((await page.title()) === 'Google', 'Title does not match');
18
+
19
+ // Test so it does not crash
20
+ await page.setContent('<span id="icon">🎭</span>');
21
+
22
+ console.log('inside-lambda: Passed tests');
23
+ } catch (error) {
24
+ throw error;
25
+ } finally {
26
+ if (browser !== null) {
27
+ await browser.close();
28
+ }
29
+ }
30
+ };
@@ -1,44 +1,44 @@
1
- const playwright = require('../../dist/src/');
2
- const assert = require('assert');
3
- const fs = require('fs');
4
- const PNG = require('pngjs').PNG;
5
- const pixelmatch = require('pixelmatch');
6
-
7
- exports.handler = async (event, context) => {
8
- let browser = null;
9
-
10
- try {
11
- await playwright.loadFont(
12
- 'https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf'
13
- );
14
- const browser = await playwright.launchChromium();
15
- const context = await browser.newContext();
16
-
17
- const page = await context.newPage();
18
- await page.goto(event.url || 'https://example.com');
19
-
20
- const data = await page.screenshot();
21
- assert(data.length > 0, 'Page screenshot is empty');
22
-
23
- assert((await page.title()) === 'Google', 'Title does not match');
24
-
25
- await page.setContent('<span id="icon">🎭</span>');
26
- const emojiImage = await (await page.$('#icon')).screenshot();
27
- const img1 = PNG.sync.read(fs.readFileSync('buildbots/assets/emoji.png'));
28
- const img2 = PNG.sync.read(emojiImage);
29
- const { width, height } = img1;
30
-
31
- const imageMatches = pixelmatch(img1.data, img2.data, null, width, height, {
32
- threshold: 0.1,
33
- });
34
- assert(!imageMatches, 'font loading with emojis does not work');
35
-
36
- console.log('inside-lambda: Passed tests');
37
- } catch (error) {
38
- throw error;
39
- } finally {
40
- if (browser !== null) {
41
- await browser.close();
42
- }
43
- }
44
- };
1
+ const playwright = require('../../dist/src/');
2
+ const assert = require('assert');
3
+ const fs = require('fs');
4
+ const PNG = require('pngjs').PNG;
5
+ const pixelmatch = require('pixelmatch');
6
+
7
+ exports.handler = async (event, context) => {
8
+ let browser = null;
9
+
10
+ try {
11
+ await playwright.loadFont(
12
+ 'https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf'
13
+ );
14
+ const browser = await playwright.launchChromium();
15
+ const context = await browser.newContext();
16
+
17
+ const page = await context.newPage();
18
+ await page.goto(event.url || 'https://example.com');
19
+
20
+ const data = await page.screenshot();
21
+ assert(data.length > 0, 'Page screenshot is empty');
22
+
23
+ assert((await page.title()) === 'Google', 'Title does not match');
24
+
25
+ await page.setContent('<span id="icon">🎭</span>');
26
+ const emojiImage = await (await page.$('#icon')).screenshot();
27
+ const img1 = PNG.sync.read(fs.readFileSync('buildbots/assets/emoji.png'));
28
+ const img2 = PNG.sync.read(emojiImage);
29
+ const { width, height } = img1;
30
+
31
+ const imageMatches = pixelmatch(img1.data, img2.data, null, width, height, {
32
+ threshold: 0.1,
33
+ });
34
+ assert(!imageMatches, 'font loading with emojis does not work');
35
+
36
+ console.log('inside-lambda: Passed tests');
37
+ } catch (error) {
38
+ throw error;
39
+ } finally {
40
+ if (browser !== null) {
41
+ await browser.close();
42
+ }
43
+ }
44
+ };
package/buildbots/test.sh CHANGED
@@ -1,21 +1,21 @@
1
- #/bin/bash
2
-
3
- set -ex
4
-
5
- LOG_FILE="log.txt"
6
-
7
- function run_test {
8
- test_file="$1"
9
- echo "Testing $newfile against $oldfile"
10
-
11
- echo "Running test: $test_file"
12
- docker run --rm -v "$PWD":/var/task:delegated lambci/lambda:nodejs12.x "buildbots/assets/$test_file.handler" '{"url": "https://google.com"}' 2>&1 | tee "$LOG_FILE"
13
- grep -Fq "inside-lambda: Passed tests" "$LOG_FILE"
14
-
15
- echo "Sucessfully passed test: $test_file"
16
- }
17
-
18
- run_test "test-font"
19
- run_test "test-default"
20
-
21
- rm "$LOG_FILE"
1
+ #/bin/bash
2
+
3
+ set -ex
4
+
5
+ LOG_FILE="log.txt"
6
+
7
+ function run_test {
8
+ test_file="$1"
9
+ echo "Testing $newfile against $oldfile"
10
+
11
+ echo "Running test: $test_file"
12
+ docker run --rm -v "$PWD":/var/task:delegated lambci/lambda:nodejs12.x "buildbots/assets/$test_file.handler" '{"url": "https://google.com"}' 2>&1 | tee "$LOG_FILE"
13
+ grep -Fq "inside-lambda: Passed tests" "$LOG_FILE"
14
+
15
+ echo "Sucessfully passed test: $test_file"
16
+ }
17
+
18
+ run_test "test-font"
19
+ run_test "test-default"
20
+
21
+ rm "$LOG_FILE"
package/cortex.yaml ADDED
@@ -0,0 +1,14 @@
1
+ openapi: 3.0.1
2
+ info:
3
+ title: playwright-aws-lambda
4
+ description: >-
5
+ Support for running Microsoft's Playwrite on AWS Lambda and Google Cloud
6
+ functions
7
+ x-cortex-git:
8
+ github:
9
+ repository: JupiterOne/playwright-aws-lambda
10
+ x-cortex-owners:
11
+ - type: group
12
+ name: JupiterOne/janus
13
+ x-cortex-service-groups: tier-4
14
+ x-cortex-tag: playwright-aws-lambda
@@ -1,8 +1,8 @@
1
- import * as playwright from 'playwright-core';
2
- import { LaunchOptions } from 'playwright-core';
3
- /**
4
- * Returns a list of recommended additional Chromium flags.
5
- */
6
- export declare function getChromiumArgs(headless: boolean): string[];
7
- export declare function launchChromium(launchOptions?: Partial<LaunchOptions>): Promise<playwright.ChromiumBrowser>;
8
- export declare const loadFont: (input: string) => Promise<void>;
1
+ import * as playwright from 'playwright-core';
2
+ import { LaunchOptions } from 'playwright-core';
3
+ /**
4
+ * Returns a list of recommended additional Chromium flags.
5
+ */
6
+ export declare function getChromiumArgs(headless: boolean): string[];
7
+ export declare function launchChromium(launchOptions?: Partial<LaunchOptions>): Promise<playwright.ChromiumBrowser>;
8
+ export declare const loadFont: (input: string) => Promise<void>;
@@ -1,131 +1,131 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadFont = exports.launchChromium = exports.getChromiumArgs = void 0;
4
- const fs_1 = require("fs");
5
- const fs = require("fs");
6
- const path = require("path");
7
- const util_1 = require("util");
8
- const https = require("https");
9
- const playwright = require("playwright-core");
10
- const isLambdaRuntimeEnvironment_1 = require("./util/isLambdaRuntimeEnvironment");
11
- const isHeadlessModeEnabled_1 = require("./util/isHeadlessModeEnabled");
12
- const fileExists_1 = require("./util/fileExists");
13
- const getEnvironmentVariables_1 = require("./util/getEnvironmentVariables");
14
- const { inflate } = require('lambdafs');
15
- /**
16
- * Returns a list of recommended additional Chromium flags.
17
- */
18
- function getChromiumArgs(headless) {
19
- const result = [
20
- '--autoplay-policy=user-gesture-required',
21
- '--disable-background-networking',
22
- '--disable-background-timer-throttling',
23
- '--disable-backgrounding-occluded-windows',
24
- '--disable-breakpad',
25
- '--disable-client-side-phishing-detection',
26
- '--disable-component-update',
27
- '--disable-default-apps',
28
- '--disable-dev-shm-usage',
29
- '--disable-domain-reliability',
30
- '--disable-extensions',
31
- '--disable-features=AudioServiceOutOfProcess',
32
- '--disable-hang-monitor',
33
- '--disable-ipc-flooding-protection',
34
- '--disable-notifications',
35
- '--disable-offer-store-unmasked-wallet-cards',
36
- '--disable-popup-blocking',
37
- '--disable-print-preview',
38
- '--disable-prompt-on-repost',
39
- '--disable-renderer-backgrounding',
40
- '--disable-setuid-sandbox',
41
- '--disable-speech-api',
42
- '--disable-sync',
43
- '--disk-cache-size=33554432',
44
- '--hide-scrollbars',
45
- '--ignore-gpu-blacklist',
46
- '--metrics-recording-only',
47
- '--mute-audio',
48
- '--no-default-browser-check',
49
- '--no-first-run',
50
- '--no-pings',
51
- '--no-sandbox',
52
- '--no-zygote',
53
- '--password-store=basic',
54
- '--use-gl=swiftshader',
55
- '--use-mock-keychain',
56
- ];
57
- if (headless === true) {
58
- result.push('--single-process');
59
- }
60
- else {
61
- result.push('--start-maximized');
62
- }
63
- return result;
64
- }
65
- exports.getChromiumArgs = getChromiumArgs;
66
- async function getChromiumExecutablePath(headless) {
67
- if (headless !== true) {
68
- return undefined;
69
- }
70
- if ((await fileExists_1.default('/tmp/chromium')) === true) {
71
- for (const file of await fs_1.promises.readdir('/tmp')) {
72
- if (file.startsWith('core.chromium') === true) {
73
- await fs_1.promises.unlink(`/tmp/${file}`);
74
- }
75
- }
76
- return '/tmp/chromium';
77
- }
78
- const input = path.join(__dirname, 'bin');
79
- const promises = [
80
- inflate(`${input}/chromium.br`),
81
- inflate(`${input}/swiftshader.tar.br`),
82
- ];
83
- if (isLambdaRuntimeEnvironment_1.default()) {
84
- promises.push(inflate(`${input}/aws.tar.br`));
85
- }
86
- const result = await Promise.all(promises);
87
- return result.shift();
88
- }
89
- async function launchChromium(launchOptions) {
90
- const headless = isHeadlessModeEnabled_1.default();
91
- const args = getChromiumArgs(headless);
92
- const executablePath = await getChromiumExecutablePath(headless);
93
- const env = {
94
- ...(await getEnvironmentVariables_1.default()),
95
- ...((launchOptions === null || launchOptions === void 0 ? void 0 : launchOptions.env) || {}),
96
- };
97
- const browser = await playwright.chromium.launch({
98
- args,
99
- executablePath,
100
- headless,
101
- env,
102
- ...launchOptions,
103
- });
104
- return browser;
105
- }
106
- exports.launchChromium = launchChromium;
107
- exports.loadFont = async (input) => new Promise(async (resolve, reject) => {
108
- const url = new URL(input);
109
- const output = path.join(getEnvironmentVariables_1.AWS_FONT_DIR, url.pathname.split('/').pop());
110
- if (await util_1.promisify(fs.exists)(output)) {
111
- resolve();
112
- return;
113
- }
114
- if (!fs.existsSync(getEnvironmentVariables_1.AWS_FONT_DIR)) {
115
- await fs_1.promises.mkdir(getEnvironmentVariables_1.AWS_FONT_DIR);
116
- }
117
- const stream = fs.createWriteStream(output);
118
- stream.once('error', (error) => {
119
- return reject(error);
120
- });
121
- https.get(input, (response) => {
122
- response.on('data', (chunk) => {
123
- stream.write(chunk);
124
- });
125
- response.once('end', () => {
126
- stream.end(() => {
127
- return resolve();
128
- });
129
- });
130
- });
131
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadFont = exports.launchChromium = exports.getChromiumArgs = void 0;
4
+ const fs_1 = require("fs");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const util_1 = require("util");
8
+ const https = require("https");
9
+ const playwright = require("playwright-core");
10
+ const isLambdaRuntimeEnvironment_1 = require("./util/isLambdaRuntimeEnvironment");
11
+ const isHeadlessModeEnabled_1 = require("./util/isHeadlessModeEnabled");
12
+ const fileExists_1 = require("./util/fileExists");
13
+ const getEnvironmentVariables_1 = require("./util/getEnvironmentVariables");
14
+ const { inflate } = require('lambdafs');
15
+ /**
16
+ * Returns a list of recommended additional Chromium flags.
17
+ */
18
+ function getChromiumArgs(headless) {
19
+ const result = [
20
+ '--autoplay-policy=user-gesture-required',
21
+ '--disable-background-networking',
22
+ '--disable-background-timer-throttling',
23
+ '--disable-backgrounding-occluded-windows',
24
+ '--disable-breakpad',
25
+ '--disable-client-side-phishing-detection',
26
+ '--disable-component-update',
27
+ '--disable-default-apps',
28
+ '--disable-dev-shm-usage',
29
+ '--disable-domain-reliability',
30
+ '--disable-extensions',
31
+ '--disable-features=AudioServiceOutOfProcess',
32
+ '--disable-hang-monitor',
33
+ '--disable-ipc-flooding-protection',
34
+ '--disable-notifications',
35
+ '--disable-offer-store-unmasked-wallet-cards',
36
+ '--disable-popup-blocking',
37
+ '--disable-print-preview',
38
+ '--disable-prompt-on-repost',
39
+ '--disable-renderer-backgrounding',
40
+ '--disable-setuid-sandbox',
41
+ '--disable-speech-api',
42
+ '--disable-sync',
43
+ '--disk-cache-size=33554432',
44
+ '--hide-scrollbars',
45
+ '--ignore-gpu-blacklist',
46
+ '--metrics-recording-only',
47
+ '--mute-audio',
48
+ '--no-default-browser-check',
49
+ '--no-first-run',
50
+ '--no-pings',
51
+ '--no-sandbox',
52
+ '--no-zygote',
53
+ '--password-store=basic',
54
+ '--use-gl=swiftshader',
55
+ '--use-mock-keychain',
56
+ ];
57
+ if (headless === true) {
58
+ result.push('--single-process');
59
+ }
60
+ else {
61
+ result.push('--start-maximized');
62
+ }
63
+ return result;
64
+ }
65
+ exports.getChromiumArgs = getChromiumArgs;
66
+ async function getChromiumExecutablePath(headless) {
67
+ if (headless !== true) {
68
+ return undefined;
69
+ }
70
+ if ((await fileExists_1.default('/tmp/chromium')) === true) {
71
+ for (const file of await fs_1.promises.readdir('/tmp')) {
72
+ if (file.startsWith('core.chromium') === true) {
73
+ await fs_1.promises.unlink(`/tmp/${file}`);
74
+ }
75
+ }
76
+ return '/tmp/chromium';
77
+ }
78
+ const input = path.join(__dirname, 'bin');
79
+ const promises = [
80
+ inflate(`${input}/chromium.br`),
81
+ inflate(`${input}/swiftshader.tar.br`),
82
+ ];
83
+ if (isLambdaRuntimeEnvironment_1.default()) {
84
+ promises.push(inflate(`${input}/aws.tar.br`));
85
+ }
86
+ const result = await Promise.all(promises);
87
+ return result.shift();
88
+ }
89
+ async function launchChromium(launchOptions) {
90
+ const headless = isHeadlessModeEnabled_1.default();
91
+ const args = getChromiumArgs(headless);
92
+ const executablePath = await getChromiumExecutablePath(headless);
93
+ const env = {
94
+ ...(await getEnvironmentVariables_1.default()),
95
+ ...((launchOptions === null || launchOptions === void 0 ? void 0 : launchOptions.env) || {}),
96
+ };
97
+ const browser = await playwright.chromium.launch({
98
+ args,
99
+ executablePath,
100
+ headless,
101
+ env,
102
+ ...launchOptions,
103
+ });
104
+ return browser;
105
+ }
106
+ exports.launchChromium = launchChromium;
107
+ exports.loadFont = async (input) => new Promise(async (resolve, reject) => {
108
+ const url = new URL(input);
109
+ const output = path.join(getEnvironmentVariables_1.AWS_FONT_DIR, url.pathname.split('/').pop());
110
+ if (await util_1.promisify(fs.exists)(output)) {
111
+ resolve();
112
+ return;
113
+ }
114
+ if (!fs.existsSync(getEnvironmentVariables_1.AWS_FONT_DIR)) {
115
+ await fs_1.promises.mkdir(getEnvironmentVariables_1.AWS_FONT_DIR);
116
+ }
117
+ const stream = fs.createWriteStream(output);
118
+ stream.once('error', (error) => {
119
+ return reject(error);
120
+ });
121
+ https.get(input, (response) => {
122
+ response.on('data', (chunk) => {
123
+ stream.write(chunk);
124
+ });
125
+ response.once('end', () => {
126
+ stream.end(() => {
127
+ return resolve();
128
+ });
129
+ });
130
+ });
131
+ });
@@ -1 +1 @@
1
- export * from './chromium';
1
+ export * from './chromium';
package/dist/src/index.js CHANGED
@@ -1,13 +1,13 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./chromium"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./chromium"), exports);
@@ -1 +1 @@
1
- export default function fileExists(path: string): Promise<boolean>;
1
+ export default function fileExists(path: string): Promise<boolean>;
@@ -1,13 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs_1 = require("fs");
4
- async function fileExists(path) {
5
- try {
6
- await fs_1.promises.access(path);
7
- return true;
8
- }
9
- catch (err) {
10
- return false;
11
- }
12
- }
13
- exports.default = fileExists;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs_1 = require("fs");
4
+ async function fileExists(path) {
5
+ try {
6
+ await fs_1.promises.access(path);
7
+ return true;
8
+ }
9
+ catch (err) {
10
+ return false;
11
+ }
12
+ }
13
+ exports.default = fileExists;
@@ -1,3 +1,3 @@
1
- export declare const AWS_TMP_DIR = "/tmp/aws";
2
- export declare const AWS_FONT_DIR = "/tmp/fonts";
3
- export default function getEnvironmentVariables(): Promise<Record<string, string>>;
1
+ export declare const AWS_TMP_DIR = "/tmp/aws";
2
+ export declare const AWS_FONT_DIR = "/tmp/fonts";
3
+ export default function getEnvironmentVariables(): Promise<Record<string, string>>;
@@ -1,41 +1,41 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AWS_FONT_DIR = exports.AWS_TMP_DIR = void 0;
4
- const fs_1 = require("fs");
5
- const path = require("path");
6
- const isLambdaRuntimeEnvironment_1 = require("./isLambdaRuntimeEnvironment");
7
- exports.AWS_TMP_DIR = '/tmp/aws';
8
- exports.AWS_FONT_DIR = '/tmp/fonts';
9
- const AWS_LIB_DIR = `${exports.AWS_TMP_DIR}/lib`;
10
- async function getEnvironmentVariables() {
11
- if (!isLambdaRuntimeEnvironment_1.default()) {
12
- return {};
13
- }
14
- const env = {};
15
- // If Chromium will be initialized without an FONTCONFIG_PATH or empty it crashes. To prevent
16
- // that we only set the custom font directory if the custom directory was created (by loadFont function)
17
- // alternatively set it to a non-existing directory.
18
- if (!process.env.FONTCONFIG_PATH && fs_1.existsSync(exports.AWS_FONT_DIR)) {
19
- env.FONTCONFIG_PATH = exports.AWS_FONT_DIR;
20
- await fs_1.promises.writeFile(path.join(exports.AWS_FONT_DIR, 'fonts.conf'), `<?xml version="1.0"?>
21
- <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
22
- <fontconfig>
23
- <dir>${exports.AWS_FONT_DIR}</dir>
24
- <cachedir>/tmp/fonts-cache/</cachedir>
25
- <config></config>
26
- </fontconfig>`);
27
- }
28
- else {
29
- env.FONTCONFIG_PATH = exports.AWS_TMP_DIR;
30
- }
31
- if (!process.env.LD_LIBRARY_PATH) {
32
- env.LD_LIBRARY_PATH = AWS_LIB_DIR;
33
- }
34
- else if (!process.env.LD_LIBRARY_PATH.startsWith(AWS_LIB_DIR)) {
35
- env.LD_LIBRARY_PATH = [
36
- ...new Set([AWS_LIB_DIR, ...process.env.LD_LIBRARY_PATH.split(':')]),
37
- ].join(':');
38
- }
39
- return env;
40
- }
41
- exports.default = getEnvironmentVariables;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AWS_FONT_DIR = exports.AWS_TMP_DIR = void 0;
4
+ const fs_1 = require("fs");
5
+ const path = require("path");
6
+ const isLambdaRuntimeEnvironment_1 = require("./isLambdaRuntimeEnvironment");
7
+ exports.AWS_TMP_DIR = '/tmp/aws';
8
+ exports.AWS_FONT_DIR = '/tmp/fonts';
9
+ const AWS_LIB_DIR = `${exports.AWS_TMP_DIR}/lib`;
10
+ async function getEnvironmentVariables() {
11
+ if (!isLambdaRuntimeEnvironment_1.default()) {
12
+ return {};
13
+ }
14
+ const env = {};
15
+ // If Chromium will be initialized without an FONTCONFIG_PATH or empty it crashes. To prevent
16
+ // that we only set the custom font directory if the custom directory was created (by loadFont function)
17
+ // alternatively set it to a non-existing directory.
18
+ if (!process.env.FONTCONFIG_PATH && fs_1.existsSync(exports.AWS_FONT_DIR)) {
19
+ env.FONTCONFIG_PATH = exports.AWS_FONT_DIR;
20
+ await fs_1.promises.writeFile(path.join(exports.AWS_FONT_DIR, 'fonts.conf'), `<?xml version="1.0"?>
21
+ <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
22
+ <fontconfig>
23
+ <dir>${exports.AWS_FONT_DIR}</dir>
24
+ <cachedir>/tmp/fonts-cache/</cachedir>
25
+ <config></config>
26
+ </fontconfig>`);
27
+ }
28
+ else {
29
+ env.FONTCONFIG_PATH = exports.AWS_TMP_DIR;
30
+ }
31
+ if (!process.env.LD_LIBRARY_PATH) {
32
+ env.LD_LIBRARY_PATH = AWS_LIB_DIR;
33
+ }
34
+ else if (!process.env.LD_LIBRARY_PATH.startsWith(AWS_LIB_DIR)) {
35
+ env.LD_LIBRARY_PATH = [
36
+ ...new Set([AWS_LIB_DIR, ...process.env.LD_LIBRARY_PATH.split(':')]),
37
+ ].join(':');
38
+ }
39
+ return env;
40
+ }
41
+ exports.default = getEnvironmentVariables;
@@ -1 +1 @@
1
- export default function isHeadlessModeEnabled(): boolean;
1
+ export default function isHeadlessModeEnabled(): boolean;
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function isHeadlessModeEnabled() {
4
- if (process.env.IS_LOCAL !== undefined) {
5
- return false;
6
- }
7
- return ['AWS_LAMBDA_FUNCTION_NAME', 'FUNCTION_NAME', 'FUNCTION_TARGET'].some(key => process.env[key] !== undefined);
8
- }
9
- exports.default = isHeadlessModeEnabled;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isHeadlessModeEnabled() {
4
+ if (process.env.IS_LOCAL !== undefined) {
5
+ return false;
6
+ }
7
+ return ['AWS_LAMBDA_FUNCTION_NAME', 'FUNCTION_NAME', 'FUNCTION_TARGET'].some(key => process.env[key] !== undefined);
8
+ }
9
+ exports.default = isHeadlessModeEnabled;
@@ -1 +1 @@
1
- export default function isLambdaRuntimeEnvironment(): boolean;
1
+ export default function isLambdaRuntimeEnvironment(): boolean;
@@ -1,11 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function isLambdaRuntimeEnvironment() {
4
- return [
5
- 'AWS_Lambda_nodejs10.x',
6
- 'AWS_Lambda_nodejs12.x',
7
- 'AWS_Lambda_nodejs14.x',
8
- 'AWS_Lambda_nodejs16.x',
9
- ].includes(process.env.AWS_EXECUTION_ENV);
10
- }
11
- exports.default = isLambdaRuntimeEnvironment;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isLambdaRuntimeEnvironment() {
4
+ return [
5
+ 'AWS_Lambda_nodejs10.x',
6
+ 'AWS_Lambda_nodejs12.x',
7
+ 'AWS_Lambda_nodejs14.x',
8
+ 'AWS_Lambda_nodejs16.x',
9
+ 'AWS_Lambda_nodejs18.x',
10
+ ].includes(process.env.AWS_EXECUTION_ENV);
11
+ }
12
+ exports.default = isLambdaRuntimeEnvironment;
package/package.json CHANGED
@@ -1,47 +1,53 @@
1
- {
2
- "name": "@oro-dxeco/playwright-aws-lambda",
3
- "version": "0.9.2",
4
- "description": "Support for running Microsoft's Playwrite on AWS Lambda and Google Cloud functions",
5
- "main": "./dist/src/",
6
- "author": "ORO <oro_dxeco@jp.oro.com>",
7
- "license": "MIT",
8
- "publishConfig": {
9
- "access": "public"
10
- },
11
- "engines": {
12
- "node": ">= 8.0.0"
13
- },
14
- "scripts": {
15
- "compile-src-cjs": "tsc --declaration --declarationDir ./dist -p tsconfig-src-cjs.json && cp -R ./src/bin ./dist/src",
16
- "precompile-src": "rm -rf ./dist",
17
- "compile-src": "npm run compile-src-cjs",
18
- "lint": "tslint --format codeFrame --project tsconfig.json 'src/**/*.ts' 'test/**/*.ts'",
19
- "pretest": "npm run lint",
20
- "test": "jest",
21
- "build": "npm run compile-src",
22
- "format-code": "prettier --write '**/*.[jt]s'"
23
- },
24
- "dependencies": {
25
- "lambdafs": "^2.1.1"
26
- },
27
- "peerDependencies": {
28
- "playwright-core": "^1"
29
- },
30
- "devDependencies": {
31
- "@types/debug": "^4.1.5",
32
- "@types/jest": "^26.0.9",
33
- "@types/node": "~14",
34
- "husky": "^4.2.5",
35
- "jest": "^26.3.0",
36
- "lint-staged": "10.2.11",
37
- "nodemon": "^2.0.4",
38
- "pixelmatch": "^5.2.1",
39
- "playwright-core": "^1.3.0",
40
- "pngjs": "^5.0.0",
41
- "prettier": "^2.0.5",
42
- "ts-jest": "^26.2.0",
43
- "tslint": "^6.1.3",
44
- "tslint-config-prettier": "^1.18.0",
45
- "typescript": "^3.9.7"
46
- }
47
- }
1
+ {
2
+ "name": "@oro-dxeco/playwright-aws-lambda",
3
+ "version": "0.11.0",
4
+ "description": "Support for running Microsoft's Playwrite on AWS Lambda and Google Cloud functions",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/JupiterOne/playwright-aws-lambda"
8
+ },
9
+ "license": "MIT",
10
+ "main": "./dist/src/",
11
+ "author": "ORO <oro_dxeco@jp.oro.com>",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "engines": {
16
+ "node": ">= 8.0.0"
17
+ },
18
+ "scripts": {
19
+ "compile-src-cjs": "tsc --declaration --declarationDir ./dist -p tsconfig-src-cjs.json && cpx ./src/bin ./dist/src",
20
+ "precompile-src": "rimraf ./dist",
21
+ "compile-src": "npm run compile-src-cjs",
22
+ "lint": "tslint --format codeFrame --project tsconfig.json 'src/**/*.ts' 'test/**/*.ts'",
23
+ "pretest": "npm run lint",
24
+ "test": "jest",
25
+ "build": "npm run compile-src",
26
+ "format-code": "prettier --write '**/*.[jt]s'"
27
+ },
28
+ "dependencies": {
29
+ "lambdafs": "^2.1.1"
30
+ },
31
+ "peerDependencies": {
32
+ "playwright-core": "^1"
33
+ },
34
+ "devDependencies": {
35
+ "@types/debug": "^4.1.5",
36
+ "@types/jest": "^26.0.9",
37
+ "@types/node": "~14",
38
+ "cpx": "^1.5.0",
39
+ "husky": "^4.2.5",
40
+ "jest": "^26.3.0",
41
+ "lint-staged": "10.2.11",
42
+ "nodemon": "^2.0.4",
43
+ "pixelmatch": "^5.2.1",
44
+ "playwright-core": "^1.3.0",
45
+ "pngjs": "^5.0.0",
46
+ "prettier": "^2.0.5",
47
+ "rimraf": "^5.0.5",
48
+ "ts-jest": "^26.2.0",
49
+ "tslint": "^6.1.3",
50
+ "tslint-config-prettier": "^1.18.0",
51
+ "typescript": "^3.9.7"
52
+ }
53
+ }
Binary file
Binary file
Binary file