Disable a web extension toolbar button except for specific domains - google-chrome

I'm writing a web extension at the moment that should have a toolbar button, but should be disabled except for a handful of frequently visited sites. However, I can't find a way to indicate to the browser that it should enable the toolbar button selectively based on domain matching.
While I can restrict the content_scripts section using the "matches": [...] syntax, the background script will (of course) load universally, but there does not appear to be a way to specify in the manifest.json that there should be domain restrictions.
Alternatively, is there a simple way to tell the browser to disable a toolbar button (or swap out its graphic) unless the active tab's location matches a domain for running the extension's actions are meaningful? Looking at something like NoScript this should be possible, but I can't find any mention, let alone example, of how that might be done on MDN.

Related

Can I label browser tabs across-origins?

I have a number of embedded devices with a web-based front end, each on a different randomly assigned ip address.
I often want to check between these devices but, when they're open in different tabs, it is hard to tell which is which.
I have attempted to embed these pages in iframes with a header labelling each one, but CORS prevented the pages from showing.
Is there a way I could get the opening page to label a tab or window to help me distinguish between similar looking pages? Failing that, and possibly in SuperUser territory, is there any way I could manually label the tabs in my browser once they're open?
Here's a partial answer. There are a number of third-party plugins for Chrome which allow the user to manually rename tabs. I have installed one called Simple Tab Renamer and it seems to be doing the job.
An automated system would be nicer, but I suspect security policies would prevent that.
https://chrome.google.com/webstore/detail/simple-tab-renamer/ailhpmlejogfdcpoflidmobgkgdemaog

Does content script have access to newtab page?

Updated
Thanks #kofifus for the info, Chrome as of 61 explicitly forbids content scripts on its default new tab page
Previous
Say I have the following sample extension, it will output test in console.
manifest.json
{
"name": "Test",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content.js"
]
}
]
}
content.js
console.log('test');
Will above extension work well in chrome://newtab page?
Some helpful info:
I know by default chrome extension can't access to chrome:// pages, and we could change this behavior through chrome://flags/#extensions-on-chrome-urls
chrome://newtab in fact is a url like https://www.google.co.jp/_/chrome/newtab?espv=2&ie=UTF-8, so it shouldn't be blocked by above restriction.
There are many mouse gestures extension available, like crxMouse, they work well on chrome://newtab page
There are also some voices saying it's not allowed to inject content scripts in chrome://newtab, for example, #Xan's comments below this answer
and this author's case
So it looks weird as its different behavior across different devices( or settings?). Is there any official statements about whether content scripts can run in chrome://newtab pages? Or is there a setting we could change this behavior?
Chrome as of 61 explicitly forbids content scripts on its default new tab page
Q: Is there any official statements about whether content scripts can run in chrome://newtab pages?
A: Not really, but Google's documentation states that:
Host permissions and content script matching are based on a set of URLs defined by match patterns. A match pattern is essentially a URL that begins with a permitted scheme (http, https, file, or ftp, and that can contain '*' characters. The special pattern matches any URL that starts with a permitted scheme.
chrome://newtab only redirects the user to whatever url is set as the new tab page. Usually it will redirect the user to https://<your local google domain>/_/chrome/newtab(a permitted match pattern). But if another extension sets the new tab page to customNewTab.html, then chrome://newtab will redirect the user to chrome-extension://chrome-id/customNewTab.html, and any other extension's content scripts will not be able to run on the new tab.
This SA question also confirms this. If you try adding "exclude_matches": ["*://*/_/chrome/newtab*"], to your manifest, the content script will stop working on the new tab page.
Q: Is there a setting that could change this behavior?
None beside an override page set by another extension. (Note that themes only change the appearance of the new tab, and won't override the new tab url)
Q: Will above extension work well in chrome://newtab page?
A: yes, unless that tab was overriden by another extension.
I have a 30,000 user extension called Screen Shader on the extension store with a huge variety of different chrome versions and a few different browsers, and so far no one has complained about it not working on the new tab page, when they complain a lot about other things.
I'm not too sure why other people think it shouldn't work on the new tab page, but hopefully this answered all the questions you were having.
On a sidenote: Keypress problems with the new tab page
On his blogpost at http://www.toptip.ca/2010/01/google-chrome-content-script.html the developer of "Boss Key and Button" complains about issues with running a content script in the new tab page. His extension minimizes all chrome windows and opens the one you are currently on in a new tab whenever you press F9. He thought the content script didn't work on the new tab page because whenever he used his shortcut in the new tab page, nothing happened. He failed to realize that the reason it wasn't working on the new tab page was because chrome redirects any keypresses to the browser bar so his content script could not capture the keypress.
Try using his extension and pressing F9 on a random page. All chrome windows will be minimized. go back to that random page, and click in the address bar and try pressing F9. This time nothing will happen.

Google Chrome - Extension vs App

I want to modify chrome start page, change background and maybe logo.
I want to include jQuery in users local storage and load it while users page loads ( search page )
I never done anything with chrome so I want some way where to start. Do I go reading with apps or extensions?
As a rule of thumb: Choose an app if you want to develop an (independent) application that can stand on its own. If you want to interact with the browser (e.g. modify a web page), build an extension.
In your case, you definitely need an extension.
Change start page - use chrome_url_overrides in the manifest file to override newtab.
Locally store jQuery: Although it's possible to store jQuery in local storage, you're probably fine with packaging jQuery with your extension.
To add it to your user's "search page", you have to use a content script. By default, content scripts run in an execution environment that is different from the page (the document's DOM is shared though). Usually, this behavior is desired. If you really want to expose the jQuery library to the scripts in the page, take a look at this answer.
If you really want to load some script from a remote location and use it as a content script, read Chrome extension adding external javascript to current page's html.
I'm not sure what you mean by "change background and maybe logo". If you're referring to the browser's appearance, the only option to do that is by creating a theme. This must be a separate extension.

Is it possible to hide extension resources in the Chrome web inspector network tab?

When I'm viewing the downloaded resources for a page in the Chrome web inspector, I also see the HTML/JS/CSS requested by certain extensions.
In the example above, indicator.html, indicator.js and indicator.css are actually part of the Readability Chrome extension, not part of my app.
This isn't too big a deal in this particular situation, but on a more complex page and with several extensions installed, it can get quite crowded in there!
I was wondering if there was a way to filter out any extension-related resources from this list (i.e. any requests using the chrome-extension:// protocol).
Does anyone know how I could achieve this?
Not quite the solution I was after (I'd have preferred a global setting), but there is now a way to filter out requests from extensions, as mentioned by a commenter on the issue I originally opened.
In the network tab filter box, enter the string -scheme:chrome-extension (as shown below):
This is case-sensitive, so make sure it's lowercase. Doing this will hide all resources which were requested by extensions.
Just enter "-f" in Network field
Was having the same question when my extension adds a lot of noise in the network tab.
Some extensions also fire a lot of data like data:text/image etc, you can append more filter with - like:
-scheme:chrome-extension -scheme:data
Another way to get the http/https requests is to just use scheme:https without - because the resources that extensions request are usually from their local bundle:
scheme:https
An Incognito Window, can be configured to include or exclude extensions from the extensions page of Chrome settings.
One alternative is to go to "Network Request blocking" tab and add "chrome-extension:" to the list, thus extension requests will be blocked and coloured red so it's easy to visually filter them out.
you can simply enable this option and requests from extension will be group.
Update: It can only group requests that create by the extension that draw iframe, such as cVim

Creating a Badge-less Google Chrome Extension

According to the docs I have made an Google Chrome Extension that I would describe as a "browser action" because it is present on all pages. However, my extension doesn't require any interaction so having a badge next to the omnibox is pretty wasteful. I have installed extensions that do not appear anywhere (except maybe in the context menu). How is that done and is that best practice?
Having page action or browser action icons is totally optional if you don't have any popup attached to them, so just remove the whole browser_action section from your manifest file.