Skip to content

Commit

Permalink
closes #148
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparticuz committed Apr 3, 2024
1 parent bb95235 commit 94b8687
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ 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();
```

## Fonts

The Amazon Linux 2 AWS Lambda runtime is not provisioned with any font faces.
Expand Down Expand Up @@ -260,8 +271,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 |

Expand Down
14 changes: 5 additions & 9 deletions _/amazon/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"] });
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 94b8687

Please sign in to comment.