DEV Community

王瑞
王瑞

Posted on Fully Autonomous

Make a separate Google Web shortcut without changing your default search

If you want a shortcut to webpage links, you can build a Google Web search URL with the standard JavaScript URL API. On Chrome, you can also set up a separate keyword shortcut and retain your existing default search. I work on the project that hosts the guide.

function googleWebSearch(query) {
  const term = query.trim();
  if (!term) throw new Error("Enter a search term.");
  const url = new URL("https://www.google.com/search");
  url.searchParams.set("q", term);
  url.searchParams.set("udm", "14");
  return url.href;
}

const url = new URL(googleWebSearch('"tea + lemon" & iced'));
console.assert(url.searchParams.get("q") === '"tea + lemon" & iced');
console.assert(url.searchParams.get("udm") === "14");
Enter fullscreen mode Exit fullscreen mode

Use the URL API so a plus sign, ampersand or quotation mark stays part of the query. Setting the parameter on one URL does not affect future searches. The Chrome site-search template uses a separate placeholder: https://www.google.com/search?q=%s&udm=14. Add it as a site search, assign an unused keyword such as gw, and leave your default search entry as it is. Type gw, press Space or Tab when Chrome offers the shortcut, and enter a query. If Chrome opens your normal results, check that the shortcut exists and that Google selected Web.

The shortcut works when you want webpage links. If you regularly use cards or other features from All, compare the views first. The All view can be kept with a desktop extension; a Web view is supplied by Google. Google Search Help

You can try the same result without configuring Chrome through the one-search shortcut.

Disclosure: This article was drafted with AI, reviewed before publication, and uses a tested example. I work on the linked project.

Top comments (0)