11/* eslint-disable functional/no-expression-statements */
22import { type APIRoute } from 'astro'
3- import puppeteer from 'puppeteer-core '
4- import chromium from "@sparticuz/ chromium-min" ;
3+ import chromium from '@sparticuz/chromium-min '
4+ import { Chromium } from '../../libs/ chromium.ts'
55
66const exePath =
77 process . platform === 'win32'
@@ -10,10 +10,8 @@ const exePath =
1010 ? '/usr/bin/google-chrome'
1111 : '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
1212
13-
14-
15- const chromiumPack = "https://github.com/Sparticuz/chromium/releases/download/v121.0.0/chromium-v121.0.0-pack.tar"
16-
13+ const chromiumPack =
14+ 'https://github.com/Sparticuz/chromium/releases/download/v121.0.0/chromium-v121.0.0-pack.tar'
1715
1816const Localoptions = {
1917 args : [ ] ,
@@ -43,7 +41,7 @@ export const GET: APIRoute = async ({ url }) => {
4341 return new Response ( 'Invalid URL format' , { status : 400 } )
4442 }
4543
46- const browser = await puppeteer . launch ( options )
44+ const browser = await Chromium . getInstance ( options )
4745 const page = await browser . newPage ( )
4846
4947 // set the viewport size
@@ -62,15 +60,16 @@ export const GET: APIRoute = async ({ url }) => {
6260 } )
6361
6462 // close the browser
65- await browser . close ( )
63+ // to reuse the instance, now commented out.
64+ // await browser.close()
6665
6766 // Return the PNG image as the response
6867 return new Response ( file , {
6968 status : 200 ,
7069 headers : {
7170 'Content-Type' : 'image/png' ,
72- 'access-control-allow-origin' : '*' ,
73- 'cache-control' : `public, max-age=31536000` ,
71+ 'access-control-allow-origin' : '*' ,
72+ 'cache-control' : `public, max-age=31536000` ,
7473 } ,
7574 } )
7675 } catch ( error ) {
0 commit comments