Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Launch Chromium with API Keys on Mac OS X and Windows

Sometimes you need to use API Keys to use things like the Speech API. And then you Google a bit and follow all the instructions. But the Chromium Project's API Keys page does a not-so-great of explaining how to do this, so I will.

  1. Download Chromium.
  2. You'll notice a yellow disclaimer message appear as a doorhanger: Google API Keys are missing. Some functionality of Chromium will be disabled. Learn More.
  3. Clicking on that link takes you to the confusing API Keys docs page.
  4. If you aren't already, subscribe to the chromium-dev@chromium.org mailing list. (You can just subscribe to the list and choose to not receive any mail. FYI: the Chromium project restricts the APIs to those subscribed to that group - that is, Chromium devs.)
  5. Make sure you are logged in with the Google account associated with the email address that you used to subscribe to chromium-dev.
  6. Log in to the Google Cloud Platform, and select an existing project or press the "Create Project" button.
  7. From the project's API Manager, select the Credentials tab in the sidebar.
  8. Create a Browser API Key.
  9. You'll see a modal with an API key. Copy and paste that somewhere.
  10. Now create an OAuth Client ID.
  11. After you complete all the steps and the "content screen," you'll be presented with a modal with your Google Client ID and Client Secret.
  12. You'll need to set three environment variables:

On Windows: Launch cmd.exe and enter the following commands:

setx GOOGLE_API_KEY your_key_goes_here
setx GOOGLE_DEFAULT_CLIENT_ID your_client_id_goes_here
setx GOOGLE_DEFAULT_CLIENT_SECRET your_client_secret_goes_here

On Mac OS X / Linux: Plop these in your ~/.profile file:

export GOOGLE_API_KEY="your_key_goes_here"
export GOOGLE_DEFAULT_CLIENT_ID="your_client_id_goes_here"
export GOOGLE_DEFAULT_CLIENT_SECRET="your_client_secret_goes_here"
  1. Now launch Chromium:

    On Windows: Launch Chromium normally.

    On Mac OS X:

    /Applications/Chromium.app/Contents/MacOS/Chromium
@tad-lispy

This comment has been minimized.

Copy link

@tad-lispy tad-lispy commented Feb 28, 2017

Thank you. Works as expected.

I took a liberty of republishing your answer on superuser.com (with due credit), as it seems to be much easier to find there.

You may consider to use launchctl setenv command on OSX to avoid exposing keys and secrets in the shell environment (or publishing them if one is keeping dot files in public repo).

@beardypig

This comment has been minimized.

Copy link

@beardypig beardypig commented Apr 26, 2017

If you use launchctl setenv it will also work when launching Chromium from spotlight or the dock.

You can add the following to /etc/launchd.conf.

setenv GOOGLE_API_KEY "xxx"
setenv GOOGLE_DEFAULT_CLIENT_ID "xxxxx.apps.googleusercontent.com"
setenv GOOGLE_DEFAULT_CLIENT_SECRET "xxx"
@luokuning

This comment has been minimized.

Copy link

@luokuning luokuning commented Jun 8, 2017

Nice explanation, thanks!

@ezeeyahoo

This comment has been minimized.

Copy link

@ezeeyahoo ezeeyahoo commented Jun 17, 2017

/etc/launchd.conf method is not working under Sierra 10.12.5, left with launchctl setenv method

@ezeeyahoo

This comment has been minimized.

Copy link

@ezeeyahoo ezeeyahoo commented Jun 29, 2017

On Sierra, I am not able to do it using launchd.conf

Here is my work-around:-
1)mv /Applications/Chromium.app/Contents/MacOS/Chromium /Applications/Chromium.app/Contents/MacOS/Chromium_bin

2)I have created a script and placed it inside /Applications/Chromium.app/Contents/MacOS/ with name Chromium, recheck in getinfo once:-

#!/bin/bash

# Set up environment variables
export GOOGLE_API_KEY=""
export GOOGLE_DEFAULT_CLIENT_ID=""
export GOOGLE_DEFAULT_CLIENT_SECRET=""

# Launch Chromium
/Applications/Chromium.app/Contents/MacOS/Chromium_bin
  1. Give it +x permission

It is working fine.

  1. I have made another script in icloud to restore above setting after every version update
@uBlock-user

This comment has been minimized.

Copy link

@uBlock-user uBlock-user commented Jul 22, 2017

@cvan This doesn't work for built in translation for Chromium. I followed the steps and installed the keys and secret, but when I right click and click on Translate in English it fails.

To reproduce go to - http://blast.hk/

Open the context menu via a right click and click on Translate in English, it will fail with a notification from the browser

Open the console via F12 and you will find this - Failed to load resource: the server responded with a status of 403 ()

PS - This only happens to me on Chromium and not Chrome. Why ? Please explain.

@Maxouhell

This comment has been minimized.

Copy link

@Maxouhell Maxouhell commented Dec 4, 2017

Didn't work here.
I tried with MacOs and Windows 10.

Chromium doesn't show Google API Keys are missing. Some functionality of Chromium will be disabled. anymore, but I have a SpeechRecognitionError with only network description.
It's working on Chrome, and i can't find out why...

Any Idea ?

@ezeeyahoo

This comment has been minimized.

Copy link

@ezeeyahoo ezeeyahoo commented Jan 17, 2018

I have made this process lot easier for MAC https://github.com/ezeeyahoo/ChromiumSyncEnabler

@BasmaRG

This comment has been minimized.

Copy link

@BasmaRG BasmaRG commented Feb 3, 2018

Thanks a lot, It is very useful.

@vusdo

This comment has been minimized.

Copy link

@vusdo vusdo commented Jun 1, 2018

I am using Ubuntu 16.04.
export or /etc/chrome_dev.conf I tried both, but the existing key value
It is not replaced.

I want to know how to replace api-key.

@uBlock-user

This comment has been minimized.

Copy link

@uBlock-user uBlock-user commented Aug 7, 2018

This is my followup response to my previous post where I couldn't get built in google translate to work which I finally am able to now. You need to Enable an API named Chrome Translate Element via https://console.cloud.google.com/apis/api/translateelement.googleapis.com/ and wait for a minute to get it working on Chromium.

@htr3n

This comment has been minimized.

Copy link

@htr3n htr3n commented Jul 5, 2019

Hi all,

the aforementioned method with launchctl setenv does not work under macOS Mojave (10.14) for me. Renaming binary Chromium and using special scripts to launch it still works, I suppose, but will be overwritten in the next Chromium upgrade? I have found some less intrusive ways that works in many macOS including Mojave. I noted them in this post.

Cheers,
Huy

@htr3n

This comment has been minimized.

Copy link

@htr3n htr3n commented Oct 14, 2019

@alswl: I'm not sure touching the bundle is better (never try nor want to) as it's will be overwritten in the next update/upgrade? How can it sustain upgrading Chromium in macOS?

As far as Chromium still honours environment variables, setting environment variables still works, I suppose.

@alswl

This comment has been minimized.

Copy link

@alswl alswl commented Oct 14, 2019

@alswl: I'm not sure touching the bundle is better (never try nor want to) as it's will be overwritten in the next update/upgrade? How can it sustain upgrading Chromium in macOS?

As far as Chromium still honours environment variables, setting environment variables still works, I suppose.

Yes, it will be modified exactly if upgrade. All files in the Chrome.app is not stable if upgrade.

But there is better solution than modify launch entry point. Because there are many ways to launch the application, eg. multiple arguments.
Maybe your launch script should use $@ to propagate the arguments.

@lopugit

This comment has been minimized.

Copy link

@lopugit lopugit commented Dec 15, 2019

I have made this process lot easier for MAC https://github.com/ezeeyahoo/ChromiumSyncEnabler

Dude thank you so much!!! Epic!!!!!!!!

@gsitreble2019

This comment has been minimized.

Copy link

@gsitreble2019 gsitreble2019 commented Apr 4, 2021

fix for chromium sync here... (Warning use a different account with 2FA not your main account for playing around. You do not want AI/ML ban your account forever). Just use a dummy account.

If you reached this gist because Google stopped chromium sync (1,2) you can solve this problem for Ubuntu or similar linux

Update you latest ubuntu (stable from repo)

apt-cache policy chromium-browser
chromium-browser:
  Installed: 89.0.4389.90-0ubuntu0.18.04.2
  Candidate: 89.0.4389.90-0ubuntu0.18.04.2
apt-get install chromium-browser

Subscribe to mailing list (as stated in gist 1). Then you just enable Chrome Sync API at https://console.cloud.google.com/apis/library/chromesync.googleapis.com
Now create all the GOOGLE_API_KEY GOOGLE_DEFAULT_CLIENT_ID GOOGLE_DEFAULT_CLIENT_SECRET keys as shown above. I used TV-and-Limited-Input-devices when Creating OAuth client ID. Not sure that matters

In ubuntu edit file:

/etc/chromium-browser/default
Add lines:

##all these are random numbers from a cat typing my keyboard so please do try them in production if you have free time...

GOOGLE_API_KEY=AIzazUdJiNwlR6zYtNd
GOOGLE_DEFAULT_CLIENT_ID=83728372837-wn4AKjPv02YM1x4gv.apps.googleusercontent.com
GOOGLE_DEFAULT_CLIENT_SECRET=EERRN-JtEoGYoqL7xGZ6hhIxbM

export GOOGLE_API_KEY
export GOOGLE_DEFAULT_CLIENT_ID
export GOOGLE_DEFAULT_CLIENT_SECRET

Now either restart laptop or ideally it should source automagically.

Can any bash expert tell me why it did not work for me if I use

###DOES NOT WORK
export GOOGLE_API_KEY=AIzazUdJiNwlR6zYtNd
export GOOGLE_DEFAULT_CLIENT_ID=83728372837-wn4AKjPv02YM1x4gv.apps.googleusercontent.com
export GOOGLE_DEFAULT_CLIENT_SECRET=EERRN-JtEoGYoqL7xGZ6hhIxbM

#but doing it separately like above works fine
  1. https://askubuntu.com/questions/1322559/sync-chromium-with-a-google-account-does-not-work-any-more-solutions
  2. https://arnoldthebat.co.uk/wordpress/2021/02/10/important-update/
@DAC324

This comment has been minimized.

Copy link

@DAC324 DAC324 commented Apr 29, 2021

In Arch-based Linux distributions, Chromium and Chromium-Dev are using a special launcher that parses a configuration file for additional options.
It is ~./config/chromium-flags.conf for Chromium, and ~/.config/chromium-dev-flags.conf for Chromium-Dev. For the information discussed here, just insert the following lines into that file:
--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
--oauth2-client-id=xxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
--oauth2-client-secret=xxxxxxxxxxxxxxxxxxx
Of course, replace those xxx by your actual data.
Unfortunately, I did not find an option to insert the API Key there as well, so it looks like in Arch and Manjaro, you will have to amend /etc/environment to include
GOOGLE_API_KEY=xxxxxxxxxxxxxxxxxxx

@IamCarbonMan

This comment has been minimized.

Copy link

@IamCarbonMan IamCarbonMan commented May 2, 2021

Sync still isn't working for me. Chromium no longer complains about not having API keys and now has a "turn on sync" button but after clicking it and logging in with Google it takes me back to new tab and nothing has changed.

@bogdan-13

This comment has been minimized.

Copy link

@bogdan-13 bogdan-13 commented May 2, 2021

Sync still isn't working for me. Chromium no longer complains about not having API keys and now has a "turn on sync" button but after clicking it and logging in with Google it takes me back to new tab and nothing has changed.

Signing in to Chromium is restricted
Signing in to Chromium requires an OAuth 2.0 token for authentication. As this OAuth 2.0 token gives access to various Google services that handle user data (e.g. Chrome sync), for security and privacy reasons the generation of this OAuth 2.0 token is restricted. This means that signing in to Chromium is restricted (as the OAuth 2.0 token cannot be generated). In order to sign in to Chromium builds, please add your test account to google-browser-signin-testaccounts@chromium.org (accounts in this group are allowed to get access tokens bypassing the restriction above).

It works ;)

@hariskar

This comment has been minimized.

Copy link

@hariskar hariskar commented May 8, 2021

I want to create OAuth client ID for Chromium on Android. What Application type should I choose when I create the OAuth client ID?
I chose "Web Application" and sync does not work. I have completed all previous steps.
Thank you for guide!

@gsitreble2019

This comment has been minimized.

Copy link

@gsitreble2019 gsitreble2019 commented May 13, 2021

https://groups.google.com/a/chromium.org/g/google-browser-signin-testaccounts/about?pli=1

Sync still isn't working for me. Chromium no longer complains about not having API keys and now has a "turn on sync" button but after clicking it and logging in with Google it takes me back to new tab and nothing has changed.

Signing in to Chromium is restricted
Signing in to Chromium requires an OAuth 2.0 token for authentication. As this OAuth 2.0 token gives access to various Google services that handle user data (e.g. Chrome sync), for security and privacy reasons the generation of this OAuth 2.0 token is restricted. This means that signing in to Chromium is restricted (as the OAuth 2.0 token cannot be generated). In order to sign in to Chromium builds, please add your test account to google-browser-signin-testaccounts@chromium.org (accounts in this group are allowed to get access tokens bypassing the restriction above).

It works ;)

Sync still isn't working for me. Chromium no longer complains about not having API keys and now has a "turn on sync" button but after clicking it and logging in with Google it takes me back to new tab and nothing has changed.

Signing in to Chromium is restricted
Signing in to Chromium requires an OAuth 2.0 token for authentication. As this OAuth 2.0 token gives access to various Google services that handle user data (e.g. Chrome sync), for security and privacy reasons the generation of this OAuth 2.0 token is restricted. This means that signing in to Chromium is restricted (as the OAuth 2.0 token cannot be generated). In order to sign in to Chromium builds, please add your test account to google-browser-signin-testaccounts@chromium.org (accounts in this group are allowed to get access tokens bypassing the restriction above).

Click on the link below

https://groups.google.com/a/chromium.org/g/google-browser-signin-testaccounts/about?pli=1

@AkiSakurai

This comment has been minimized.

Copy link

@AkiSakurai AkiSakurai commented Jun 13, 2021

I want to create OAuth client ID for Chromium on Android. What Application type should I choose when I create the OAuth client ID?
I chose "Web Application" and sync does not work. I have completed all previous steps.
Thank you for guide!

Android chromium use GoogleAuthUtil to retrieve tokens. It does not use outh client Id specified in args.gn, instead it delegate the process to google play services, which is guarded by whitelisting fingerprint of apps signature. Currently it is restricted to official build only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment