I have a Chrome Extension and I added a managed_schema to define a property (SomeSetting) so I can set it via a policy.
manifest.json:
"storage": { "managed_schema": "schema.json" }
schema.json:
"properties": { "SomeSetting": { "type": "string" } }
I can see SomeSetting in chrome://policy/ but I have no idea how to set the value. Apparently I can do this at HKLM\SOFTWARE\Policies\Google\Chrome\3rdparty\extensions... but I tried and it never is shown as set in chrome://policy/.
Does anyone know if this is suppose to work? Does it have to be HKCU instead? Or do I need Active Directory because setting values locally via the registry is not supported?
I had a hard time figuring this out. The documentation is not all that clear.
In order to get your schema to work you need to add a registry entry for "SomeSetting".
Go to the following item in your registry (create the necessary items):
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\3rdparty\extensions\aaaaaaaaaaaaaa\policy
where aaaaaaaaaaaaaa is your extension ID from chrome://extensions
Right-click on "policy" and create a new string value:
Name: SomeSetting
Data: "some value"
Go back to Chrome and reload chrome://policy/
The new policy should appear.
From your extension, you can access the value like this:
chrome.storage.managed.get("SomeSetting", function(setting_val) {
console.debug(setting_val);
});
I'm not sure if this requires Active Directory to work.
It was mentioned in Alternative Extension Distribution Options that:
Google Chrome supports the following extension installation methods:
Using a preferences JSON file (for Mac OS X and Linux only)
Using the Windows registry (for Windows only)
More information regarding other mechanisms on extensions distribution options can be found in the documentation.
Related
I need to support multiple settings file for different environment, e.g. Dev, Prod, for Azure Functions.
Below is what I tried, I want to find out if it is possible to make the settings file loaded automicatlly without step 2, and 3, like ASP.NET CORE 2.x.
Step 1: The settings files below are defined,
MyAppSettings.development.json
{
ThirdParty: {
"Key": "Key1"
}
}
MyAppSettings.production.json
{
ThirdParty: {
"Key": "Key2"
}
}
Step 2: Define an environment variable that is used to load the settings file
Settings_File_To_Load: MyAppSettings.development.json
Is it possible to reuse a variable instead of creating a new one, e.g. ASPNETCORE_ENVIRONMENT
Step 3: Read the value of "Settings_File_To_Load", and load the content of the file.
Is it possible to let the file automicatlly loaded?
Again, is it possible to make the settings file loaded automicatlly without step 2, and 3?
Visual studio 2017
There is no automatic override for the settings file- the runtime is expecting local.settings.json and you must override this if you want to use multiple settings files in local development.
If you are changing the settings as part of publishing the solution to Azure, you can override the settings in the local.settings.json as part of the publish profile. You can use the slots feature in Azure Functions to allow for multiple configs/environments within the service.
I am trying to configure an extension using the method described at Manifest for storage areas
. I'm pretty sure I have everything set up correctly, but I am not seeing the policy value in chrome://policy(it is shown as Not set) and, obviously, there is no policy seen from
chrome.storage.managed.get(null,(d)=>{console.log(d)});
I've checked my schema and the config file I uploaded in the Admin Panel at https://www.jsonschemavalidator.net and it seems to match. It's very simple, schema.json is
{
"type" : "object",
"properties" : {
"PolicyTest" : {
"type" : "string"
}
}
}
and in the json file
{
"PolicyTest" : "test"
}
Before I spend a bunch of time debugging this, I thought I would quickly ask- could this be because the extension that I am configuring this for is not hosted on the Chrome Web Store? It's hosted myself using the method described at Autoupdating.
Other than that, I'm not really sure why this isn't working- the device running Chrome is Linux, although I have also checked on a managed Chromebook, and I've checked things like making sure I've selected the right OU, refreshing the policy, and so on.
Ok, I figured it out by reference to the Chromium documentation. To answer the question in my title- yes, it works fine for extensions not hosted on the Web Store, I just had the wrong format for my options.
Basically, my json file didn't actually match the schema. For the schema I posted in my question, you actually need this :
{
"PolicyTest" : {
"Value" : "test"
}
}
Basically, your properties need to be an object with a Value field. The core sentence that I missed is : The txt file should contain a valid JSON object, mapping a policy name to an object describing the policy.
Mea cupla, I should have read the documentation more carefully. It's quite frustrating that the official Chrome extension developer documentation doesn't have a simple example of a schema and a matching config file, since there is no UI feedback if your format is wrong.
I note also there was some plan to publish a tool to build a template from a schema. I guess that never happened, it would be useful too.
I have tried to create a sample program using Node.js, following instructions from https://developers.google.com/google-apps/activity/v1/quickstart/nodejs
I throws an error saying cannot read property 'client_secret' of undefined when trying to run it.
Looking for your valuable suggestions.
Thanks in advance.
var clientSecret = credentials.installed.client_secret;
In this line credentials is pointing to client_secret.json so the first key has to be "installed". In my case the key was "web" and that was causing the error. I just renamed the key "web" to "installed".
Since there is no key named "installed", it's parsing it to be undefined.
In credentials.json change the key "web" to "installed". Probably the docs need to change from Google's side.
Before
After
It seems you have missed Step 1: Turn on the Google Apps Activity API.
After creating the Credentials:
f. Click the file_download (Download JSON) button to the right of the
client ID.
g. Move this file to your working directory and rename it
client_secret.json. Put it in your project folder.
Your client_secret.json file needs to have the line below:
"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]
instead of the lines like below:
"javascript_origins":
[
"http://localhost:8080",
"http://localhost:1453",
"http://127.0.0.1:1453",
"http://localhost"
]
Also you may want to change chain head in client_secret.json from web to installed, or vise versa.
I had this problem, but I had the wrong type of credentials file. I initially used "Web Server (Nodejs)...", and it had the "web" heading instead of the "installed", but when I did it again, and selected "Windows UI (cmd line)", I got the file with the correct format.
Try selecting the application type "Other".
Select the "Help me choose" option and there you can chose other application type.
That way your client_secret.json will have the variable named "installed".
The recent version of Google Drive API will have a Desktop client option while creating OAuth API Key. Do select that, it will have all required information to access Google drive from Script.
Is there a way to detect whether I'm running an extension that was installed from my .crx file or the extension was loaded as via 'Load unpacked extension...' button?
I'm aware about ID differences in that case, but I don't want to rely on hardcoded strings in the code.
If by "installed from my .crx file" you mean installed from Chrome Web Store you can simply check extension manifest.json for value of update_url attribute. CWS adds it when you upload your extension.
If you have a self-hosted .crx file, get your extension information using chrome.management.getSelf() and check installType of returned ExtensionInfo object. If it says "development" that means that extension was loaded unpacked in developer mode. "normal" means that it was installed from .crx file.
Here is a code sample how to do this:
function isDevMode() {
return !('update_url' in chrome.runtime.getManifest());
}
or
const isProdMode = 'update_url' in chrome.runtime.getManifest()
An extension is running in developer mode (i.e. unpacked), when it does not contain the update_url field in its manifest.
This works because an unpacked extension's JSON manifest file should not contain the update_url field. This field is automatically added when publishing via the Chrome Developer Dashboard.
For example, debug logs that only appear during development.
const IS_DEV_MODE = !('update_url' in chrome.runtime.getManifest());
function debugLog(str) {
if (IS_DEV_MODE) console.log(str);
}
debugLog('This only appears in developer mode');
In my Chrome Extension, I am using webkitNotifications.createNotification to alert users. It's a great tool!! In the sample code given, the first parameter is optional and specifies an an icon and the Google instructions claim that it can be a local reference. When I use a local file, I get a broken image link. This even occurs when I use the sample for Notification Demo located here - http://code.google.com/chrome/extensions/samples.html#f799e26ceef2367cf836f24bcb47df4398b0df58
Does anyone else have this issue?
The icon is listed in my manifest file.
I can get around this by using a complete web reference, but I like to use this tool for error notifications and sometimes the error is caused by an interruption of internet access.
I am using chrome version 18.0.1025.151 m.
Thanks!
The problem with their sample is they have included "manifest_version": 2 in their manifest but not added a "web_accessible_resources" listing what resources should be available to pages.
You can read more about manifest_version 2 and what changes it introduces here....
http://code.google.com/chrome/extensions/manifestVersion.html
...and about web_accessible_resources here....
http://code.google.com/chrome/extensions/manifest.html#web_accessible_resources
To fix the problem in the sample, you can either remove the manifest version 2 bit (even the docs say this wont be required for a while yet). Or you can add the following to the manifest....
"web_accessible_resources": [
"48.png"
]
"Web Accessible" means the resources is being accessed from your server so you must make sure to include the path to the resources in your javascript and in the manifest,json.