heroshot 0.14.2 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -190,7 +190,7 @@ const resizeActionSchema = z.object({
190
190
  }).describe("Resize the browser viewport mid-flow.");
191
191
  const hideActionSchema = z.object({
192
192
  type: z.literal("hide"),
193
- selectors: z.array(z.string()).describe("Element selectors to hide (display: none)")
193
+ selectors: z.array(z.string()).describe("Element selectors to hide (visibility: hidden)")
194
194
  }).describe("Hide elements from screenshot. Use to remove cookie banners, chat widgets, ads.");
195
195
  /** Union of all supported action types. Actions execute sequentially before screenshot. */
196
196
  const actionSchema = z.discriminatedUnion("type", [
@@ -370,7 +370,8 @@ const configSchema = z.object({
370
370
  jpegQuality: z.number().int().min(1).max(100).default(80).describe("JPEG compression quality (1-100), only used when outputFormat is \"jpeg\""),
371
371
  browser: browserSchema.optional().describe("Default browser settings applied to all screenshots"),
372
372
  workers: z.number().int().min(1).optional().describe("Number of parallel capture workers (default: 1)"),
373
- screenshots: z.array(screenshotSchema).default([]).describe("Screenshot definitions")
373
+ screenshots: z.array(screenshotSchema).default([]).describe("Screenshot definitions"),
374
+ hiddenElements: z.record(z.string(), z.array(z.string())).optional().describe("Elements to hide per domain (hostname → CSS selectors)")
374
375
  });
375
376
 
376
377
  //#endregion
@@ -793,7 +794,8 @@ function buildCaptureOptions(config, viewportOnly) {
793
794
  return {
794
795
  format: config.outputFormat ?? "png",
795
796
  quality: config.jpegQuality,
796
- fullPage: !viewportOnly
797
+ fullPage: !viewportOnly,
798
+ hiddenElements: config.hiddenElements
797
799
  };
798
800
  }
799
801
  /**
@@ -957,11 +959,11 @@ function executeHandleDialog(page, action) {
957
959
 
958
960
  //#endregion
959
961
  //#region src/sync/actions/hide.ts
960
- /** Hide elements by setting display: none */
962
+ /** Hide elements by setting visibility: hidden (preserves layout) */
961
963
  async function executeHide(page, action) {
962
964
  if (action.type !== "hide") return;
963
965
  for (const selector of action.selectors) await page.locator(selector).evaluateAll((elements) => {
964
- for (const element of elements) element.style.display = "none";
966
+ for (const element of elements) element.style.setProperty("visibility", "hidden", "important");
965
967
  });
966
968
  }
967
969
 
@@ -1861,6 +1863,14 @@ async function captureScreenshot(page, screenshot, outputDirectory, captureOptio
1861
1863
  ...navResult,
1862
1864
  filename
1863
1865
  };
1866
+ if (captureOptions.hiddenElements) {
1867
+ const { hiddenElements: hiddenByDomain } = captureOptions;
1868
+ const { hostname } = new URL(url);
1869
+ if (hiddenByDomain[hostname]?.length) await executeHide(page, {
1870
+ type: "hide",
1871
+ selectors: hiddenByDomain[hostname]
1872
+ });
1873
+ }
1864
1874
  if (screenshot.actions && screenshot.actions.length > 0) try {
1865
1875
  await executeActions(page, screenshot.actions);
1866
1876
  await page.waitForTimeout(500);