How does chrome.browserAction work? - google-chrome

Im trying to develop my first chrome extension and am running into an issue. Firstly I am using the following boilerplate as a page action:
http://extensionizr.com/!#{"modules":["browser-mode","with-persistent-bg","no-bg","with-custom-options","no-override","inject-css","inject-js","jquerymin"],"boolean_perms":["contentSettings","cookies","notifications"],"match_ptrns":[]}
In the inject.js, it downloads a list of urls from a remote server, checks the current url and if it matches it should do something. I was going to use a notification but I guess the notification comes from the current page and not the extension. So if you start the notification it will say "Do you want to enable notifications for amazon". Then I moved on to changing the icon. I would prefer doing both eventually. However, when I try and set text with the following:
chrome.browserAction.setIcon({path: 'icons/icon128-x.png'});
However, this is what I get in the console.
Uncaught TypeError: Cannot read property 'setIcon' of undefined
Any ideas?

you can't access chrome.browserAction in content.js, according to chrome extension document Content Scripts
Additionally, content script can access the following chrome APIs directly:
i18n
storage
runtime:
connect
getManifest
getURL
id
onConnect
onMessage
sendMessage
Content scripts are unable to access other APIs directly.

The extension manifest needs a "browser_action" section before the chrome.browserAction API is available to it:
Register your browser action in the extension manifest like this:
{
"name": "My extension",
...
"browser_action": {
"default_icon": { // optional
"19": "images/icon19.png", // optional
"38": "images/icon38.png" // optional
},
"default_title": "Google Mail", // optional; shown in tooltip
"default_popup": "popup.html" // optional
},
...
}
(From https://developer.chrome.com/extensions/browserAction#manifest.)

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.

Getting Unauthorized 401 for manifest.json GCM push notifications in ASP.NET

My manifest file is in the root folder, referenced in the _Layout view as following:
<link rel="manifest" href="~/manifest.json">
The file structure is as following:
{
"gcm_sender_id": "MY_Sender_Id",
"permissions": [
"gcm"
]
}
Keep getting 401 unauthorized, in chrome dev tools under the application tab, this is what I get:
When using FCM for Web, the value for gcm_sender_id is fixed. From the docs:
{
"//": "Some browsers will use this to enable push notifications.",
"//": "It is the same for all projects, this is not your project's sender ID",
"gcm_sender_id": "103953800507"
}
Don't confuse the "browser sender ID" with the project-specific sender ID value shown in your Firebase project settings. The browser sender ID for manifest.json is a fixed value, common among all FCM JavaScript clients.

Access local chrome-urls in chrome-app

How can I get access to the local chrome-urls to receive content from there? For example use an iframe for chrome://version or access the content directly with AJAX.
Any ideas? I tried the following permission:
{
"manifest_version": 2,
"app": {
"permissions": [
"chrome://*",
"chrome://version"
]
}
}
--> "Not allowed to load local resource"
I had a look at the possible permissions but didn't find anything that fits my expectation. https://developer.chrome.com/extensions/declare_permissions
Thanks a lot in advance
Nope, you can't access chrome:// URLs in an app.
It's indirectly possible in an extension through tabs API, but there's nothing for the moment that can allow an app to do that.

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

How can I include TTS in a Chrome App?

I'm trying to use text-to-speech in a Chrome app, but I'm getting an error when trying to load the app.
My manifest.json looks like this:
{
"name": "APPNAME",
"description": "DESCRIPTION",
"version": "3",
"app": {
"urls": ["APPURL"],
"launch": {"web_url": "APPURL"}
},
"icons": {"24": "icon24.png", "128": "icon128.png"},
"permissions": ["tts"]
}
The error I'm getting reads "Could not load extension from <PATH>. Access to permission 'tts' denied."
Removing the "app" part of the manifest seems to allow it to load without problems. That would make me think that TTS is limited to Chrome extensions, but the docs suggest otherwise. Changing the "tts" permission to the "cookies" permission results in the same error, but changing it to "clipboardRead" does not.
I'm attempting to load the app via: Tools > Extensions > Load unpacked extension, and I'm using Chrome 16 on Ubuntu 11.10.
Can anyone tell me what I'm doing wrong?
It turned out that some permissions are only available for extensions and packaged apps. I was trying to use tts with a webapp, which is unfortunately not available.
That said, the Web Speech API is now available, along with Speech Synthesis.