1

I am using chrome-webstore-upload-cli to automatically deploy a Chrome extension to the Chrome Web Store.

webstore upload \
  --source dist/extension.zip \
  --extension-id $CHROME_STORE_EXT_ID \
  --client-id $CHROME_STORE_CLIENT_ID \
  --client-secret $CHROME_STORE_SECRET \
  --refresh-token $CHROME_STORE_REFRESH_TOKEN \
  --auto-publish

This works fine most of the time; the extension is uploaded and published.

The Problem

However, occasionally, the extension will not be published automatically. Instead, it's "pending review", and it might be in this state for an hour or two:

Since my deployment scripts assume that the extension will be available to users once it's uploaded to the web store, this leads to errors down the line (e.g., broken links, version numbers etc.).

Is there any way I can programmatically check if the extension is actually available in a given version, or when it is?

What I've tried

I tried using curl to query the contents of the Web Store site that allows users to download the extension, but it does not actually contain the version string. At least the “Additional Information” tab is rendered dynamically and not part of the original site's source code…

I've also checked the Web Store API. It offers an Items.Get method, but it only returns the following information:

{
  "kind": "chromewebstore#item",
  "id": string,
  "publicKey": string,
  "uploadState": string,
  "itemError": [
    (value)
  ]
}

This data does not contain information about the latest published version or the review state. And anyway, the request can only be used with DRAFT resources.

slhck
  • 36,575
  • 28
  • 148
  • 201
  • Have you checked if [`chrome.runtime.onInstalled`](https://developer.chrome.com/extensions/runtime#event-onInstalled) can do some help? See [this SO post](https://stackoverflow.com/questions/2399389/detect-chrome-extension-first-run-update/14957674#14957674) for implementation. – MαπμQμαπkγVπ.0 Jun 14 '19 at 09:22
  • @MαπμQμαπkγVπ.0 I found a simple solution, see my answer below. – slhck Jun 26 '19 at 15:39

2 Answers2

1

The source HTML contains meta tags with the version, particularly:

<meta itemprop="version" content="1.20.1"/>

Now, one should not parse HTML with regular expressions, as that is very unstable. But for the purpose of this question, the following works fine:

extId="abcdefg"
curl -s -L "https://chrome.google.com/webstore/detail/$extId" | \
      grep -o -E 'content="\d+\.\d+\.\d+"' | \
      cut -d= -f2 | \
      tr -d '"'

Replace the extension ID with yours. It'll just print the version (e.g., 1.20.1).


A more stable solution would be to use, for example, Python 3 with requests and BeautifulSoup:

import requests
from bs4 import BeautifulSoup

ext_id="abcdefg"
ret = requests.get("https://chrome.google.com/webstore/detail/" + ext_id)
soup = BeautifulSoup(ret.text, 'html.parser')
version = soup.find_all("meta", attrs={"itemprop": "version"})[0]["content"]
print(version)
slhck
  • 36,575
  • 28
  • 148
  • 201
0

Detecting extension version not so hard, you can use chrome-webstore

Example usage:

var webstore = require('chrome-webstore');

async function printVersion() {
  var details = await webstore.detail({id: '<your-package-id>'});


  // returns version
  console.log(details.version);
}

printVersion();
ridvanaltun
  • 2,595
  • 2
  • 15
  • 28