This sample demonstrates the chrome.contextMenus API by letting a user search Google with region-specific parameters via a context menu.
Modern Google Search uses IP geolocation and query parameters for localization instead of domain-based routing (e.g., google.com.br). This sample reflects that reality.
The extension uses:
chrome.contextMenus.create()to populate context menu with region options- Query parameters:
cr(country restriction) andlr(language restriction) - A popup UI to enable/disable regions
chrome.contextMenus.onClicked.addListener()to open searches in new tabs
- Base URL: All searches use
https://www.google.com/search - Country Parameter (cr): Restricts results to a specific country (e.g.,
countryCAfor Canada) - Language Parameter (lr): Restricts results to a specific language (e.g.,
lang_enfor English)
While these parameters don't guarantee region-specific results (as IP geolocation is the primary factor), they're the modern, programmatic way to express regional preference to Google Search.
- Clone this repository.
- Load this directory in Chrome as an unpacked extension.
- Pin the extension to the taskbar to access the action button.
- Open the extension popup by clicking the action button to enable/disable regions.
- Select text on any webpage and right-click to access the context menu with region options.
- Click a region to search for your selected text with that region's parameters.