Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/busy-horses-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"google-sr": patch
---

Fix delay option in searchWithPages function

The delay option was previously defined in `SearchOptionsWithPages` interface but was not actually implemented in the `searchWithPages` function. This fix adds the missing delay functionality that applies the specified delay (default 1000ms) between page requests, helping to prevent rate limiting.
7 changes: 7 additions & 0 deletions packages/google-sr/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export async function searchWithPages<
: Array.from({ length: options.pages }, (_, i) => i * 10);
const baseRequestConfig = prepareRequestConfig(options);
const parsers = options.parsers || [OrganicResult];
const delay = options.delay ?? 1000;

for (const page of pages) {
// params is guaranteed to be a URLSearchParams
// setting it here should be fine
Expand All @@ -137,6 +139,11 @@ export async function searchWithPages<
}

searchResults.push(pageResults);

// Add delay after processing each page (except the last one)
if (page !== pages[pages.length - 1] && delay > 0) {
await new Promise((resolve) => setTimeout(resolve, delay));
}
}

return searchResults;
Expand Down