Skip to content

Commit

Permalink
Merge pull request #38 from cloudflare/add_keep_alive_option
Browse files Browse the repository at this point in the history
Add keep alive option
  • Loading branch information
meddulla committed May 3, 2024
2 parents 7c55764 + e07ecdc commit 433a4e7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
machine: ubuntu-latest
node: 18.18
- name: macOS
machine: macos-latest
machine: macos-13
node: 14
- name: Windows
machine: windows-latest
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflare/puppeteer",
"version": "0.0.6",
"version": "0.0.7",
"description": "A high-level API to control headless Chrome over the DevTools Protocol for use in Workers",
"keywords": [
"puppeteer",
Expand Down
15 changes: 13 additions & 2 deletions src/puppeteer-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export interface LimitsResponse {
timeUntilNextAllowedBrowserAcquisition: number;
}

export interface LaunchOptions {
keep_alive?: number; // milliseconds to keep browser alive even if it has no activity (from 10_000ms to 600_000ms, default is 60_000)
}

class PuppeteerWorkers extends Puppeteer {
public constructor() {
super({isPuppeteerCore: true});
Expand All @@ -103,8 +107,15 @@ class PuppeteerWorkers extends Puppeteer {
* @param endpoint - Cloudflare worker binding
* @returns a browser session or throws
*/
public async launch(endpoint: BrowserWorker): Promise<Browser> {
const res = await endpoint.fetch('/v1/acquire');
public async launch(
endpoint: BrowserWorker,
options?: LaunchOptions
): Promise<Browser> {
let acquireUrl = '/v1/acquire';
if (options?.keep_alive) {
acquireUrl = `${acquireUrl}?keep_alive=${options.keep_alive}`;
}
const res = await endpoint.fetch(acquireUrl);
const status = res.status;
const text = await res.text();
if (status !== 200) {
Expand Down

0 comments on commit 433a4e7

Please sign in to comment.