Matches IP address (content_scripts) - google-chrome-extension

I want next matches:
"content_scripts": [
{
"matches": ["*://1.1.1.*/*"],
"run_at": "document_end",
"all_frames": true,
"js": ["/js/jquery-3.3.1.min.js", "/js/contentScript.js"]
}
],
but error:
Invalid value for 'content_scripts[0].matches[0]': Invalid host wildcard.
How can I use 1.1.1.* ?

Related

Linking to local files within css file

I'm attempting to completely overhaul a websites css and possibly html and just trying to find a way that works for me.
The problem is that within an extension local css file I'm also trying to define a font url via extension local files.
manifest.json:
{
"name": "Test theme",
"description": "Custom theme for Darkmass.gg.",
"version": "0.0.1",
"manifest_version": 3,
"content_scripts": [
{
"matches": [
"https://*.example.com/*"
],
"css": [
"./css/main.css"
],
"js": [
"./js/app.js"
],
"run_at": "document_end"
}
],
"web_accessible_resources": [
{
"resources": [ "./media/*" ],
"matches": [ "https://*.example.com/*" ]
}
]
}
main.css:
#font-face {
font-family: NFLDolph;
src: url('chrome-extension://ipbedjgbhlnngdddbaojpnaicdpifmgd//media/fonts/NFLDOLPH.TTF');
}
The problem clearly lies with the source url for the NFLDolph font-face, if I just leave it as ./media/fonts/NFLDOLPH.ttf than it just tries to load the font from example.com instead of locally.
And here is the error I get:
Denying load of chrome-extension://ipbedjgbhlnngdddbaojpnaicdpifmgd//media/fonts/NFLDOLPH.TTF. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
I made a sample.
manifest.json
{
"name": "NFLDolph",
"version": "1.0",
"manifest_version": 3,
"content_scripts": [
{
"css": [
"main.css"
],
"matches": [
"<all_urls>"
]
}
],
"web_accessible_resources": [
{
"resources": [
"font/*.TTF"
],
"matches": [
"<all_urls>"
]
}
]
}
main.css
#font-face {
font-family: NFLDolph;
src: url("chrome-extension://__MSG_##extension_id__/font/NFLDOLPH.TTF");
}
* { font-family: NFLDolph, serif }

Run Chrome extension on every domain except one?

I need a Chrome extension to run on every domain except for one. It runs everywhere with this:
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"run_at": "document_start",
"js": ["contentScript.js"]
}
]
However adding exclude_matches seems to have no effect:
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"exclude_matches": ["http://*.mysite.com/"],
"run_at": "document_start",
"js": ["contentScript.js"]
}
]
I tried using a match pattern from these docs but the extension still loads on that page:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"exclude_matches": ["*://mozilla.org/"],
"run_at": "document_start",
"js": ["contentScript.js"]
}
],
In the official docs the example is for excluding specific pages for a domain, so maybe it can't be used in the way that I'm trying?
https://developer.chrome.com/docs/extensions/mv2/content_scripts/
{
"name": "My extension",
...
"content_scripts": [
{
"matches": ["http://*.nytimes.com/*"],
"exclude_matches": ["*://*/*business*"],
"js": ["contentScript.js"]
}
],
...
}
To run everywhere except "google" domains use exclude_globs. In manifest.json:
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"exclude_globs": ["*://*.google.*/*"],
"run_at": "document_start",
"js": ["contentScript.js"]
}
]

Injected script was not load

manifest.json
{
"manifest_version": 3,
"name": "Inject Scripts",
"version": "1.0",
"content_scripts": [{
"matches": [
"*://*/*"
],
"run_at": "document_end",
"js": [
"content.js"
]
}],
"web_accessible_resources": [{
"resources": [
"every site .js"
],
"matches": []
}]
}
content.js
document.head.insertAdjacentHTML('beforeend', ˋ<script src="${chrome.runtime.getURL('every site .js')}"></script>ˋ)
every site .js
console.log('injected')
<script> was inserted to <head> successful with the src="chrome-extension://<extension ID>/every site .js" attribute but there is neither console.log output nor Error message.
I installed my extension locally by enabling "Developer mode" and "Load unpacked" in "chrome://extensions/".
Do I need to specify "permissions" in manifest.json?

Content script for no-cookie embedded YouTube video

I want to set content script to all embedded youtube video, so i use the tag in content script:
"content_scripts": [
{
"matches": [
"*://*.youtube.com/*"
],
"css": [
"app_player.css"
],
"js": [
"content.js"
],
"run_at": "document_end",
"all_frames": true
}
]
Everything worked ok, but I see that, there two types of embedded YouTube videos: youtube.com/embed and youtube-nocookie.com. For the second one, my content script didn't work. How can I do?
The second case for embedded code as:
<video tabindex="-1" class="video-stream html5-main-video" controlslist="nodownload"
style="width: 815px; height: 458px; left: 0px; top: 19.2813px;"
src="blob:https://www.youtube-nocookie.com/85648de5-fa2c-4785-bc8c-1fdce53c8226">
</video>
Not sure if I understood the description right, but did you try this?
"content_scripts": [
{
"matches": [
"*://*.youtube.com/*",
"*://*.youtube-nocookie.com/*" // <- This did not work?
],
"css": [
"app_player.css"
],
"js": [
"content.js"
],
"run_at": "document_end",
"all_frames": true
}
]

Content Security Policy doesn't allow mixed content

I am trying to access an internal machine of my network via chrome extensions. I am calling a php file from my chrome extension. I am using manifest file as follows:
{
"content_scripts": [ {
"js": [ "lib/jquery.js", "lib/jquery-ui.js", "lib/util.js" ],
"matches": [ "*://plus.example.com/*", "*://tools.example.com/*" ]
}, {
"js": [ "tools/g_tool.js" ],
"matches": [ "*://plus.example.com/*" ]
}, {
"js": [ "tools/b_tool.js" ],
"matches": [ "*://tools.google.com/*" ]
} ],
"icons": {
"128": "images/icon_128.png",
"16": "images/icon_16.png",
"48": "images/icon_48.png"
},
"manifest_version": 2,
"name": "Tool",
"permissions": [ "*://plus.example.com/*", "*://tools.example.com/*", "http://myusername-example.com/*"],
"version": "0.7",
"web_accessible_resources": [ "images/loading.gif" ]
}
The internal machine which I am using can be used only via http. So, I am looking around for a way to use it in my chrome extension.

Resources