Match to any link in JSON - html

I am trying to make my own Chrome extension. I want to apply changes to any link. I have:
"content_scripts": [{
"matches": ["https://*"],
"css": ["main.css"]
}]
What should I write in "matches"?

Related

How to match the same domain with multiple extensions in Chrome extension?

So, I am working on a Chrome extension that needs to be activated on any site with the domain example.extension where extension can be anything(.com, .de etc.).
I have a content script and in the manifest.json I included all the domain names listed one after another:
"content_scripts": [{
"js": ["content.js"],
"matches": ["https://www.example.com/*","https://www.example.de/*"]
}]
But how could I write something that matches example.* instead of enumerating all of them?
Note that I tried something like this and it does not work:
"content_scripts": [{
"js": ["content.js"],
"matches": ["https://www.example*"]
}]
These are 2 options:
First option:
You make use of the include_globs in the manifest as shown here
"content_scripts": [{
"js": ["content.js"],
"matches": [ "*://*/*" ],
"include_globs": [
"*://*.example.*/*",
]
}]
2nd Option: You can change your content script to check if the target URL matches www.example.*:
if (window.location.host.startsWith('www.example')){
//content script code
}
You can use a persistent background script and inject the script when the url matches your requirement. For example:
background.js
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status == 'complete' && tab.url.indexOf('https://www.example.') == 0){
chrome.tabs.executeScript(tabId,{file:'content.js'});
}
});

Chrome Extension: content_scripts matches for custom new tab page

I'm trying to create a custom new tab page for Chrome. I have it in my manifest.json so that: "chrome_url_overrides": {
"newtab": "home.html"
}
It won't, however, load the scripts that I load in my home.html. I found out that you need to use content_scripts, so now I also have
"content_scripts": [
{
"matches": [""],
"css": ["style.css"],
"js": ["logic.js", "macros.js"]
}
]
What do I put in the "matches"? It doesn't allow "home.html" or "chrome://newtab".

Google Chrome - uploading apps to chrome web store but how to allow all domain with manifest.json?

I have Chrome web store package with zip file ready. But the problem is that manifest.json i need to allow two domain + all subdomains.
This is the reference:
https://developer.chrome.com/extensions/manifest
https://developer.chrome.com/extensions/content_scripts
Where its saying: "matches": ["http://www.google.com/*"]
But how do i say in matches to allow two domain with all there subdomains? example:
*.stackoverflow.com and *.centos.org?
{
"name": "My extension",
...
"content_scripts": [
{
"matches": ["http://www.google.com/*"],
"css": ["mystyles.css"],
"js": ["jquery.js", "myscript.js"]
}
],
...
}
You're looking at wrong parts of the documentation.
Match Patterns
Match patterns and globs
Note that "matches" property is an array.
"content_scripts": [
{
"matches": ["*://*.stackoverflow.com/*", "*://*.centos.org/*"],
"css": ["mystyles.css"],
"js": ["jquery.js", "myscript.js"]
}
],
The above will match all pages on stackoverflow.com, centos.org and all of their subdomains. Important to note that just stackoverflow.com will be matched.
* in place of http will match exactly either http or https.

Content script matching top-level domains like all google.*

I want my content script to match all google domains, and a specific page. I know this is not possible.
Manifest.json
"content_scripts": [{
"matches": [
,"*://www.google.*"
,"*://www.youtube.com/*"
,"*://readthedocs.org/*"]
,
....
Is there another way to do this? Just wanted to make sure before I list all domains Google has :)
Listing all Google domains is not that difficult, because Google has published a list of all public Google domains at http://www.google.com/supported_domains. Prefix every item in this list with "*://* and add the ", suffix to every item. Then copy-paste the result to your manifest file.
An alternative option is to use the "include_globs" field (this is applied after "matches"):
{
....
"content_scripts": [{
"matches": [ "*://*/*" ],
"include_globs": [
"*://*.google.*/*",
"*://*.youtube.com/*",
"*://readthedocs.org/*"
],
"js": [ "contentscript.js" ]
}]
}
(I've replaced "*://www.google.com/*" with "*://*.google.com/*, because of subdomains like https://encrypted.google.com/)

excuting javascript file into the new tab on chrome

I want to insert a javascript file into the original new tab page of chrome to be executed,
I tried this but error in matching when I'm trying to load the extension.
"content_scripts": [
{
"matches": ["chrome://newtab/*"],
"js": ["jquery.js", "myscript.js"]
}
]
You cannot do that, you need to use override pages to do this.
{
"name": "My extension",
...
"chrome_url_overrides" : {
"newtab": "myPage.html"
},
...
}
Add this to your matches: "matches": ["*://*.google.com/_/chrome/newtab*"]
That url looks like an implementation detail, so no guarantees it won't change, but for now it works.