diff --git a/README.md b/README.md index 762d902..40f1dcc 100644 --- a/README.md +++ b/README.md @@ -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. @@ -260,8 +271,8 @@ By default, this package uses `swiftshader`/`angle` to do CPU acceleration for W | `args` | `Array` | 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` | 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 | diff --git a/_/amazon/handlers/index.js b/_/amazon/handlers/index.js index f6a5124..b8c07af 100644 --- a/_/amazon/handlers/index.js +++ b/_/amazon/handlers/index.js @@ -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(); } }