Scrape Google search results using JavaScript / TypeScript
Not supported in browser environments.
If you are using CommonJS, please read the important notice about future ESM-only support.
npm install google-sr
# For pnpm/yarn/bun:
pnpm add google-sr
yarn add google-sr
bun add google-sr
import { search, OrganicResult, TranslateResult, ResultTypes } from "google-sr";
const results = await search({
query: "translate hello to japanese",
// Explicitly specify the results you want
parsers: [TranslateResult, OrganicResult],
});
console.log(results[0].type === ResultTypes.TranslateResult); // true
console.log(results); // see below
[
{
// type property is present in all results
type: 'TRANSLATE',
sourceLanguage: 'English (detected)',
translationLanguage: 'Japanese',
sourceText: 'hello',
translatedText: 'こんにちは'
},
{
type: 'ORGANIC',
link: '...',
description: "Konnichiwa – ...",
title: '18 ...'
},
// ... and more
]
Additional examples can be found in apps/examples directory
This package currently includes both CommonJS (CJS) and ES Modules (ESM) builds.
Starting with v7.x (subject to change), we plan to drop CJS support and publish only ESM-only builds.
- Modern JavaScript: ESM is now the standard, offering better support for tree-shaking and static analysis.
- Reduces package size: Maintaining a single build reduces package size and build complexity.
- Node.js
v20
+ supports require() on ESM modules natively (no flags needed)
While Node.js v20 already supports ESM well, we will wait until its End-of-Life before removing CJS to give users and tooling more time to transition.
Note: This applies only to Node.js users, other runtimes like Bun and Deno already support ESM natively
See this gist for future migration tips and our GitHub discussion for more details.
Tests are written using vitest and can be run by using the test
script.
pnpm run test
This project is not sponsored, endorsed, or affiliated with Google in any way.
This repository is provided "as is" without warranty of any kind and is intended solely for educational and research purposes. The authors and contributors assume no responsibility for any issues, damages, or losses that may arise from its use.
By using this project, you acknowledge that you are solely responsible for complying with applicable laws and platform Terms of Service. Use at your own discretion and risk.
This repository and the code inside it is licensed under the Apache-2.0 License. Read LICENSE for more information.
Want to support the project? Star it on GitHub ★