GHC 2016-12-24

2 comments.

, https://git.io/vMvhm in timqian/star-history-plugin
> You added a background.js which seems will be run on every site, though it is not much load, but not very good. I don't know if it is nessesary for a page action?

I'm not a Chrome extension expert, but the nature of page actions dictates that there must be code executed for every page in order to determine whether the page action should be shown. Here `background.js` is not persistent (`"persistent": false` in `manifest.json`), so although there's a background page, it only takes up resources when the `chrome.tabs.onUpdated` event listener is triggered, and very briefly each time.

By the way, I just updated `background.js` slightly to only do a regex match on the URL when the URL has actually changed.

Chrome Dev site has some sample page actions here: https://developer.chrome.com/extensions/samples#search:pageaction. Looking at the samples, I realized that other than manually adding a listener to `chrome.tabs.onUpdated`, we can also use the [`declarativeContent` API](https://developer.chrome.com/extensions/declarativeContent). Here's the sample `background.js` from the "Page action by URL" example:

```js
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// When the extension is installed or upgraded ...
chrome.runtime.onInstalled.addListener(function() {
  // Replace all rules ...
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    // With a new rule ...
    chrome.declarativeContent.onPageChanged.addRules([
      {
        // That fires when a page's URL contains a 'g' ...
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { urlContains: 'g' },
          })
        ],
        // And shows the extension's page action.
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    ]);
  });
});
```

This is probably slightly more performant. I can switch to this API if you wish.

> I roughly read through the link you provided about page action, it says the icon will turn gray for other pages. I tried your updated version, it seems always green.

That's weird.

<img width="309" alt="screen shot 2016-12-24 at 1 12 04 pm" src="https://cloud.githubusercontent.com/assets/4149852/21468400/fc0dd00a-c9dc-11e6-986d-eca95db667e7.png">
<img width="339" alt="screen shot 2016-12-24 at 1 12 28 pm" src="https://cloud.githubusercontent.com/assets/4149852/21468401/fc0f3698-c9dc-11e6-9fef-0008d7e54274.png">
<img width="523" alt="screen shot 2016-12-24 at 1 12 54 pm" src="https://cloud.githubusercontent.com/assets/4149852/21468399/fc0a3e7c-c9dc-11e6-92b2-62169e9a021a.png">

What's your Chrome version? And could you please maybe add some debug prints

```diff
diff --git a/background.js b/background.js
index f2a61e4..b6bc4cd 100644
--- a/background.js
+++ b/background.js
@@ -1,5 +1,7 @@
 chrome.tabs.onUpdated.addListener(function (tabId, change, tab) {
+  console.log('Got ' + tab.url);
   if (change.url && change.url.match(/github.com\/\S*?\/\S*?/)) {
+    console.log(tab.url + ' matches /github.com\/\S*?\/\S*?/');
     chrome.pageAction.show(tabId);
   }
 })
```

and monitor the background page's console to see what's going on?

, https://git.io/vMvgr in Homebrew/homebrew-core
I realize this won't be a popular opinion among people waiting for this PR to land, but I think setuptools should be upgraded to 32.2.0, or at least 32.1.0 to match the version in [`python.rb`](https://github.com/Homebrew/homebrew-core/blob/7330a126bf338b5216dc3b31bb65485cbedbbbf1/Formula/python.rb#L44-L47).