Merge pull request #252 from Sparticuz/fix/misc-fixes
This commit is contained in:
commit
d0543e6139
6
Makefile
6
Makefile
|
|
@ -10,6 +10,12 @@ pretest:
|
|||
test:
|
||||
sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node20
|
||||
|
||||
test16:
|
||||
sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node16
|
||||
|
||||
test18:
|
||||
sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node18
|
||||
|
||||
%.zip:
|
||||
npm install --fund=false --package-lock=false
|
||||
npm run build
|
||||
|
|
|
|||
48
README.md
48
README.md
|
|
@ -204,6 +204,50 @@ From what I can tell, `headless_shell` does not seem to include support for the
|
|||
|
||||
Try marking this package as an external. Ref: https://webpack.js.org/configuration/externals/
|
||||
|
||||
### I'm experiencing timeouts or failures closing Chromium
|
||||
|
||||
This is a common issue. Chromium sometimes opens up more pages than you ask for. You can try the following
|
||||
|
||||
```typescript
|
||||
for (const page of await browser.pages()) {
|
||||
await page.close();
|
||||
}
|
||||
await browser.close();
|
||||
```
|
||||
|
||||
You can also try the following if one of the calls is hanging for some reason.
|
||||
|
||||
```typescript
|
||||
await Promise.race([browser.close(), browser.close(), browser.close()]);
|
||||
```
|
||||
|
||||
Always `await browser.close()`, even if your script is returning an error.
|
||||
|
||||
### I need Accessible pdf files
|
||||
|
||||
This is due to the way @sparticuz/chromium is built. If you require accessible pdf's, you'll need to
|
||||
recompile chromium yourself with the following patch. You can then use that binary with @sparticuz/chromium-min.
|
||||
|
||||
_Note_: This will increase the time required to generate a PDF.
|
||||
|
||||
```patch
|
||||
diff --git a/_/ansible/plays/chromium.yml b/_/ansible/plays/chromium.yml
|
||||
index b42c740..49111d7 100644
|
||||
--- a/_/ansible/plays/chromium.yml
|
||||
+++ b/_/ansible/plays/chromium.yml
|
||||
@@ -249,8 +249,9 @@
|
||||
blink_symbol_level = 0
|
||||
dcheck_always_on = false
|
||||
disable_histogram_support = false
|
||||
- enable_basic_print_dialog = false
|
||||
enable_basic_printing = true
|
||||
+ enable_pdf = true
|
||||
+ enable_tagged_pdf = true
|
||||
enable_keystone_registration_framework = false
|
||||
enable_linux_installer = false
|
||||
enable_media_remoting = false
|
||||
```
|
||||
|
||||
## Fonts
|
||||
|
||||
The Amazon Linux 2 AWS Lambda runtime is not provisioned with any font faces.
|
||||
|
|
@ -260,8 +304,8 @@ By default, this package uses `swiftshader`/`angle` to do CPU acceleration for W
|
|||
| `args` | `Array<string>` | Provides a list of recommended additional [Chromium flags](https://github.com/GoogleChrome/chrome-launcher/blob/master/docs/chrome-flags-for-tools.md). |
|
||||
| `defaultViewport` | `Object` | Returns a sensible default viewport for serverless. |
|
||||
| `executablePath(location?: string)` | `Promise<string>` | Returns the path the Chromium binary was extracted to. |
|
||||
| `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"shell"` |
|
||||
| `headless` | `true \| "shell"` | Returns `true` or `"shell"` depending on what version of chrome's headless you are running |
|
||||
| `setHeadlessMode` | `void` | Sets the headless mode to either `true` or `"shell"` |
|
||||
| `headless` | `true \| "shell"` | Returns `true` or `"shell"` depending on what version of chrome's headless you are running |
|
||||
| `setGraphicsMode` | `void` | Sets the graphics mode to either `true` or `false` |
|
||||
| `graphics` | `boolean` | Returns a boolean depending on whether webgl is enabled or disabled |
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const { ok } = require("assert");
|
||||
const { createHash } = require("crypto");
|
||||
const { ok } = require("node:assert");
|
||||
const { createHash } = require("node:crypto");
|
||||
const puppeteer = require("puppeteer-core");
|
||||
const chromium = require("@sparticuz/chromium");
|
||||
|
||||
|
|
@ -18,15 +18,8 @@ exports.handler = async (event, context) => {
|
|||
|
||||
console.log("Chromium version", await browser.version());
|
||||
|
||||
const contexts = [browser.defaultBrowserContext()];
|
||||
|
||||
while (contexts.length < event.length) {
|
||||
contexts.push(await browser.createBrowserContext());
|
||||
}
|
||||
|
||||
for (let context of contexts) {
|
||||
const job = event.shift();
|
||||
const page = await context.newPage();
|
||||
for (let job of event) {
|
||||
const page = await browser.newPage();
|
||||
|
||||
if (job.hasOwnProperty("url") === true) {
|
||||
await page.goto(job.url, { waitUntil: ["domcontentloaded", "load"] });
|
||||
|
|
@ -68,6 +61,9 @@ exports.handler = async (event, context) => {
|
|||
throw error.message;
|
||||
} finally {
|
||||
if (browser !== null) {
|
||||
for (const page of await browser.pages()) {
|
||||
await page.close();
|
||||
}
|
||||
await browser.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,28 +13,35 @@
|
|||
"tar-fs": "^3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node16": "^16.1.1",
|
||||
"@tsconfig/strictest": "^2.0.3",
|
||||
"@tsconfig/node16": "^16.1.3",
|
||||
"@tsconfig/node20": "^20.1.4",
|
||||
"@tsconfig/strictest": "^2.0.5",
|
||||
"@types/follow-redirects": "^1.14.4",
|
||||
"@types/node": "^20.11.30",
|
||||
"@types/node": "^20.12.3",
|
||||
"@types/tar-fs": "^2.0.4",
|
||||
"clean-modules": "^3.0.5",
|
||||
"typescript": "^5.4.2"
|
||||
"typescript": "^5.4.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16"
|
||||
}
|
||||
},
|
||||
"node_modules/@tsconfig/node16": {
|
||||
"version": "16.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-16.1.1.tgz",
|
||||
"integrity": "sha512-+pio93ejHN4nINX4pXqfnR/fPLRtJBaT4ORaa5RH0Oc1zoYmo2B2koG+M328CQhHKn1Wj6FcOxCDFXAot9NhvA==",
|
||||
"version": "16.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-16.1.3.tgz",
|
||||
"integrity": "sha512-9nTOUBn+EMKO6rtSZJk+DcqsfgtlERGT9XPJ5PRj/HNENPCBY1yu/JEj5wT6GLtbCLBO2k46SeXDaY0pjMqypw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@tsconfig/node20": {
|
||||
"version": "20.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node20/-/node20-20.1.4.tgz",
|
||||
"integrity": "sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@tsconfig/strictest": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/strictest/-/strictest-2.0.3.tgz",
|
||||
"integrity": "sha512-MroLvRhMbqtXI5WBSwoomro6OQS4xnCoudUrMb20JO0vLKUs0bAaCEcvM/immEBSJjFAK1l6jW1oAO8q3Ancrg==",
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/strictest/-/strictest-2.0.5.tgz",
|
||||
"integrity": "sha512-ec4tjL2Rr0pkZ5hww65c+EEPYwxOi4Ryv+0MtjeaSQRJyq322Q27eOQiFbuNgw2hpL4hB1/W/HBGk3VKS43osg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/follow-redirects": {
|
||||
|
|
@ -47,9 +54,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.11.30",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.30.tgz",
|
||||
"integrity": "sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==",
|
||||
"version": "20.12.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.3.tgz",
|
||||
"integrity": "sha512-sD+ia2ubTeWrOu+YMF+MTAB7E+O7qsMqAbMfW7DG3K1URwhZ5hN1pLlRVGbf4wDFzSfikL05M17EyorS86jShw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"undici-types": "~5.26.4"
|
||||
|
|
@ -299,9 +306,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.4.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.2.tgz",
|
||||
"integrity": "sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==",
|
||||
"version": "5.4.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz",
|
||||
"integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
|
|
|
|||
|
|
@ -40,13 +40,13 @@
|
|||
"tar-fs": "^3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node16": "^16.1.1",
|
||||
"@tsconfig/strictest": "^2.0.3",
|
||||
"@tsconfig/node20": "^20.1.4",
|
||||
"@tsconfig/strictest": "^2.0.5",
|
||||
"@types/follow-redirects": "^1.14.4",
|
||||
"@types/node": "^20.11.30",
|
||||
"@types/node": "^20.12.3",
|
||||
"@types/tar-fs": "^2.0.4",
|
||||
"clean-modules": "^3.0.5",
|
||||
"typescript": "^5.4.2"
|
||||
"typescript": "^5.4.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16"
|
||||
|
|
|
|||
|
|
@ -240,9 +240,11 @@ class Chromium {
|
|||
];
|
||||
|
||||
// https://chromium.googlesource.com/chromium/src/+/main/docs/gpu/swiftshader.md
|
||||
this.graphics
|
||||
? graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader")
|
||||
: graphicsFlags.push("--disable-webgl");
|
||||
// Blocked by https://github.com/Sparticuz/chromium/issues/247
|
||||
//this.graphics
|
||||
// ? graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader")
|
||||
// : graphicsFlags.push("--disable-webgl");
|
||||
graphicsFlags.push("--use-gl=angle", "--use-angle=swiftshader");
|
||||
|
||||
const insecureFlags = [
|
||||
"--allow-running-insecure-content", // https://source.chromium.org/search?q=lang:cpp+symbol:kAllowRunningInsecureContent&ss=chromium
|
||||
|
|
|
|||
|
|
@ -72,4 +72,4 @@ class LambdaFS {
|
|||
}
|
||||
}
|
||||
|
||||
export = LambdaFS;
|
||||
export default LambdaFS;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"extends": ["@tsconfig/node16/tsconfig", "@tsconfig/strictest"],
|
||||
"extends": ["@tsconfig/node20/tsconfig", "@tsconfig/strictest"],
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"lib": ["dom", "ES2021"],
|
||||
"module": "Node16",
|
||||
"moduleResolution": "Node16",
|
||||
"lib": ["dom", "ES2023"],
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"outDir": "build"
|
||||
},
|
||||
"include": ["source"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue