config.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { Page } from "playwright";
  2. export type Config = {
  3. /**
  4. * URL to start the crawl
  5. * @example "https://www.builder.io/c/docs/developers"
  6. * @default ""
  7. */
  8. url: string;
  9. /**
  10. * Pattern to match against for links on a page to subsequently crawl
  11. * @example "https://www.builder.io/c/docs/**"
  12. * @default ""
  13. */
  14. match: string | string[];
  15. /**
  16. * Selector to grab the inner text from
  17. * @example ".docs-builder-container"
  18. * @default ""
  19. */
  20. selector: string;
  21. /**
  22. * Don't crawl more than this many pages
  23. * @default 50
  24. */
  25. maxPagesToCrawl: number;
  26. /**
  27. * File name for the finished data
  28. * @default "output.json"
  29. */
  30. outputFileName: string;
  31. /** Optional cookie to be set. E.g. for Cookie Consent */
  32. cookie?: { name: string; value: string };
  33. /** Optional function to run for each page found */
  34. onVisitPage?: (options: {
  35. page: Page;
  36. pushData: (data: any) => Promise<void>;
  37. }) => Promise<void>;
  38. /** Optional timeout for waiting for a selector to appear */
  39. waitForSelectorTimeout?: number;
  40. };
  41. export const defaultConfig: Config = {
  42. url: "https://www.builder.io/c/docs/developers",
  43. match: "https://www.builder.io/c/docs/**",
  44. selector: `.docs-builder-container`,
  45. maxPagesToCrawl: 50,
  46. outputFileName: "../output.json",
  47. };