feat: add css parameter for custom CSS injection in screenshots
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 10m33s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 10m33s
This commit is contained in:
parent
1b7251fbcb
commit
0999474fbd
8 changed files with 176 additions and 17 deletions
|
|
@ -75,6 +75,11 @@ export const screenshotRouter = Router();
|
|||
* type: boolean
|
||||
* default: false
|
||||
* description: Emulate prefers-color-scheme dark mode
|
||||
* css:
|
||||
* type: string
|
||||
* maxLength: 5000
|
||||
* description: Custom CSS to inject into the page before capture (max 5000 chars)
|
||||
* example: "body { background: #1a1a2e !important; color: #eee !important }"
|
||||
* hideSelectors:
|
||||
* oneOf:
|
||||
* - type: string
|
||||
|
|
@ -234,6 +239,13 @@ export const screenshotRouter = Router();
|
|||
* enum: [load, domcontentloaded, networkidle0, networkidle2]
|
||||
* default: domcontentloaded
|
||||
* description: Page load event to wait for before capturing
|
||||
* - name: css
|
||||
* in: query
|
||||
* schema:
|
||||
* type: string
|
||||
* maxLength: 5000
|
||||
* description: Custom CSS to inject into the page before capture (max 5000 chars)
|
||||
* example: "body { background: #1a1a2e !important }"
|
||||
* - name: darkMode
|
||||
* in: query
|
||||
* schema:
|
||||
|
|
@ -318,6 +330,7 @@ async function handleScreenshotRequest(req: any, res: any) {
|
|||
cache,
|
||||
darkMode,
|
||||
hideSelectors,
|
||||
css,
|
||||
} = source;
|
||||
|
||||
if (!url || typeof url !== "string") {
|
||||
|
|
@ -325,6 +338,12 @@ async function handleScreenshotRequest(req: any, res: any) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Validate css parameter
|
||||
if (css && typeof css === 'string' && css.length > 5000) {
|
||||
res.status(400).json({ error: "css: maximum 5000 characters allowed" });
|
||||
return;
|
||||
}
|
||||
|
||||
// Normalize hideSelectors: string | string[] → string[]
|
||||
let normalizedHideSelectors: string[] | undefined;
|
||||
if (hideSelectors) {
|
||||
|
|
@ -362,6 +381,7 @@ async function handleScreenshotRequest(req: any, res: any) {
|
|||
cache,
|
||||
darkMode: darkMode === true || darkMode === "true",
|
||||
hideSelectors: normalizedHideSelectors,
|
||||
css: css || undefined,
|
||||
};
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue