xjsc16x
xjsc16x

Reputation: 278

Make a google search from chrome extension

I'm trying to write a simple chrome extension which will take input from a textbox and do a google image search and show the results in the extension's window.

I've tried using a GET form but that doesn't seem to be working at all. I'm trying to get their JSAPI (from https://developers.google.com/web-search/docs/?hl=en) and I'm getting the error "Cannot read property 'ImageSearch' of undefined" in the console.

Google seems to want me to use their custom search engine (CSE) function but it's not a website I'm doing this from it's an extension.

Upvotes: 0

Views: 3120

Answers (1)

andrewgu
andrewgu

Reputation: 1642

Instead of using the Custom Search Engine with its builder, you can use the Custom Search API, which is a customizable extension of the Custom Search Engine.

Also, a Google Chrome extension is basically a webpage with access to additional APIs and functionality (especially limited control over the user's browsing experience).


EDIT (Dec 22, 2020): As of Oct 24, 2016 it seems like Google stopped supporting their Custom Search API linked above. Refer to the updated Programmable Search Element Control API v2, which functions differently but should still answer the original question.

Relevant snippet demonstrating basic usage of the new API, modified from the linked page:

<!-- Put the following javascript before the closing </head> tag
and replace 123:456 with your own Programmable Search Engine ID. -->
<!-- NOTE: I've replaced "123:456" with the example ID from the documentation page -->
<script async src="https://cse.google.com/cse.js?cx=000888210889775888983:y9tkcjel090"></script>

<!-- Place this tag where you want both of the search box and the search results to render -->
<div class="gcse-search"></div>

Upvotes: 2

Related Questions