Fetch Google Search results via Chrome extension - google-chrome

I am writing a chrome extension and I need to search a string in Google search engine and check if it appears among the first 10 results.
I have tried to use google search API but it didn't work, I used the following:
chrome.search.query({queryinfo:"search_string"});
And I get:
Error in event handler: TypeError: Cannot read properties of undefined (reading 'query')
any ideas?

you must use "text" and no "queryinfo"
chrome.search.query({text:"search_string"});
And you must used in manifest.json permission :
"permissions": [
"search"
]

Related

Where can you find or how can you create a chrome extension key and place it in your manifest.json file?

Looking to implement Oauth2 in my Chrome extension
I have been researching how to implement oauth2 on a chrome extension. I have been stuck for quite some time. I eventually got information to use chrome.identity in my background.ts file.
Here is my manifest.json
...
"permissions": [
"identity"
],
"oauth2": {
"client_id": "855289137547-bd37ghe68neqevqs47esitvc99rb5f8d.apps.googleusercontent.com",
"scopes":["https://www.googleapis.com/auth/userinfo.email"]
},
"background": {
"scripts": [
"background.js",
"runtime.js"
]
},
...
Call the chrome.identity API
There is a method on the API that is called getAuthToken which I am trying to call. When I try to call this method I get the following:
// background.ts
chrome.identity.getAuthToken({ interactive: true }, (token) => {
// store token here
});
Error
Unchecked runtime.lastError: OAuth2 request failed: Service responded with error: 'bad client id: 855289137522-bd37ggg68neqevqs47esitvc99rb5f8d.apps.googleusercontent.com'.
I checked multiple times and I can confirm that that the id is the same as I my console developer credentials.
Maybe it needs a key in the manifest
I was assuming that I have to have a key in my manifest.json. So, I followed the documentation at the following link where it says to follow the steps:
At the Developer Dashboard, click Add new item.
Click Choose file and select the .zip extension directory and upload it.
Without filling in additional fields, select Save Draft and return to dashboard.
Find the extension under Your Listings and click on more info. From the popup, copy the public key and add it to the manifest inside the unzipped directory under the "key" field.
However, I looked everywhere but could not find the "more info" link or any other info leading me to a key.
Key is available in the new UI --> Package on left side menu --> Public Key
At of time of my post (August 2020), if you go to the Developer Dashboard, you will always be directed to the new UI, which doesn't contain the More Information section, which means you can't find the public key.
AFAIK there is no other way to get the public key. You can't substitute your application ID because it is a hashed version of the public key,
Look for the Welcome popup on the bottom left corner of the screen and click on opt out link in tiny font to revert to the legacy interface.

GMail Google Apps Script Plugin "The value returned from Apps Script has a type that cannot be used by the add-ons platform"

In the last 24 hours, a previously working GMail plugin I run has started failing.
I stripped it all the way down to only trying to get the example from the docs working:
var action = CardService.newAction().setFunctionName('composeEmailCallback');
CardService.newTextButton()
.setText('Compose Email')
.setComposeAction(action, CardService.ComposedEmailType.REPLY_AS_DRAFT);
// ...
function composeEmailCallback() {
var thread = GmailApp.getThreadById(e.threadId);
var draft = thread.createDraftReply('This is a reply');
return CardService.newComposeActionResponseBuilder()
.setGmailDraft(draft)
.build();
}
On BUILD (not on button press), the previously working GMail Addon displays the error message:
The value returned from Apps Script has a type that cannot be used by the add-ons platform. Also make sure to call build on any builder before returning it. Value: values {
proto_value {
type_url: "type.googleapis.com/caribou.api.proto.addons.templates.publicapi.ContextualAddOnMarkup.Card"
value: "...(omitted)"
}
}
Is this a new, known issue? Does anyone have some troubleshooting steps to share?
For me the error was was caused by open links not being whitelisted. For example, if you have code like this:
CardService.newOpenLink().setUrl(url)
Then the link returned by 'url' has to be whitelisted in the appscript manifest's openLinkUrlPrefixes list, like so:
"openLinkUrlPrefixes": [
"https://*.example.com"
]
This problem is caused by Google's silent upgrading of Apps Script to the V8 Runtime. To downgrade from this runtime to the old runtime (Rhino), perform this set of actions:
Run -> Disable New Apps Script runtime powered by Chrome V8
A related issue can be found here.

"No matching signature" error on adding a chrome.webRequest listener

I have this code:
chrome.webRequest.onCompleted.addListener(function(details){
console.log(details);
});
I'm trying to understand and use the chrome.webRequest API. I can't figure why the code isn't working, I just wanna give a try to the API by logging all the requests made by chrome. I've set the permissions in my manifest on these two patterns http://*/* and https://*/* but i will always get this error from my background script: Uncaught TypeError: No matching signature. Any help is appreciated.
"No matching signature" means you're passing the wrong parameters. As you can see in the documentation's concepts and examples you need to specify at least two parameters. The documentation for individual methods doesn't mention that which is really confusing, and you can report it on https://crbug.com.
chrome.webRequest.onCompleted.addListener(
function(details) {
console.log(details);
},
{urls: ["<all_urls>"]}
);
To view the background script's console see this answer.

Search on global properties

Is it possible to do a search using the API on metadata in the properties template? I'm using the mdfilters parameter for the search request:
https://api.box.com/2.0/search?mdfilters=[{"templateKey":"properties", "scope":"global", "filters":{"docId": "1"}}]
The response I get is 404 Not Found:
{
"message": "Instance not found for '\\\"view\\\", \\\"typeKeyKey\\\", \\\"properties\\\", \\\"searchFilterPanel\\\"'",
"code": "tuple_not_found",
"request_id": "870411128557159b487c8a"
}
I suspect that the properties template cannot be used in a metadata search, is this correct?
No, not with mdfilters. Use a regular search instead. See this answer for more.

Google Drive SDK - DrEdit Python - Web Store Manifest

I've been trying to work through the DrEdit python example for the Google Drive SDK. When I get to step 4, create a web store listing, I'm encountering a problem. I modified the manifest.json file as described. However, after I create the manifest.zip file, I am unable to upload the manifest archive from the web store developer dashboard. I receive the following error message:
"An error occurred: Invalid manifest. If your manifest includes comments, please remove them as our gallery does not support them yet."
Now, if I remove the 'container' and 'api_console_project_id' entries from the manifest, it uploads fine. However, without these entries, the DrEdit application will not be "integrated into Google Drive", correct?
I also tried to install the manifest in Google Chrome directly (developer mode). In this case, I get warnings about the two entries in question (not recognized).
How do I resolve this issue? Is it possible that the "Setting up the sample application" documentation is out of date?
(edit)
Manifest File:
{
"name" : "DrEdit",
"version" : "1.0.0.0",
"manifest_version": 2,
"description" : "Test Google Drive application",
"container" : "GOOGLE_DRIVE",
"api_console_project_id" : "dpederson-gae-dredit-api",
"icons": {
"128": "icon-128.png"
},
"app" : {
"launch" : {
"web_url" : "https://dpederson-gae-dredit.appspot.com"
}
}
}
The api_console_project_id field is invalid. It should match the App ID value from the Drive SDK tab of the APIs Console, the one you got when registering the app as explained at https://developers.google.com/drive/register
It should match the CLIENT_ID. More exactly the xxxxxxxx part from the xxxxxxxxx.apps.googleusercontent.com