I am trying to offer a free trial for my Chrome extension and am following the Chrome documentation on how to do this.
When loading my extension, the background script logs the following error on the console:
Disabled runtime.lastError when running identity.getAuthToken: OAuth2 is not provided or is not canceled.
The console points to calling chrome.identity.getAuthToken as the culprit. Here is the corresponding code in my background script:
var CWS_LICENSE_API_URL = 'https://www.googleapis.com/chromewebstore/v1.1/userlicenses/'; chrome.identity.getAuthToken({ 'interactive': false }, function(token) { console.log('token', token); var req = new XMLHttpRequest(); req.open('GET', CWS_LICENSE_API_URL + chrome.runtime.id); req.setRequestHeader('Authorization', 'Bearer ' + token); req.onreadystatechange = function() { if (req.readyState == 4) { var license = JSON.parse(req.responseText); console.log('license', license); } }; req.send(); });
My manifest is set up like this (some snippets are omitted for brevity):
"manifest_version": 2, "key": "kkkkkkkkkkkkkkk", "background": { "scripts": [ "background.js" ] }, "permissions": [ "storage", "identity", "https://www.googleapis.com/" ], "oauth2": { "client_id": "cccccccccc.apps.googleusercontent.com", "scopes": [ "https://www.googleapis.com/auth/chromewebstore.readonly" ] }
Here is what I tried or confirmed:
- The client ID matches the value in the Google Developer Console that was generated using my extension ID.
- The Chrome Web Store API is enabled in the Google Developer Console (this is the only API available).
- The manifest key corresponds to the value generated after I put the extension in the web store.
- A call to
getAuthToken with interactive mode enabled results in the same error. - I compared my code with in this example , and nothing jumps out at me as significantly different (although an extra pair of eyes to confirm will not “hurt”).
In case that matters, I use Chrome 42.0.2311.135 (64-bit) on Mac OS X.
Any ideas on what causes the error, and what do I need to change to get it gone so that I can find the token and authorization license?
Erik gillespie
source share