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
}
]
Related
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 }
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"]
}
]
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?
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.* ?
I have the following manifest to run on every page load.
The problem is that it is running only when refreshing the page.
The myscript.js will not work when I click on a link and navigate, again, only on refresh.
Why is that?
Thanks
{
"name": "BrowserActionExtension",
"version": "0.0.1",
"manifest_version": 2,
"browser_action": {
"default_title": "That's the tool tip",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"js": [ "myscript.js" ],
"run_at": "document_end"
}
],
"permissions": [
"tabs",
"<all_urls>"
]
}
If the page contains frames and the link on which you click does not belong to the top frame you get this behaviour.
Take a look to all_frames
This value is always false, but if you set this to true the script is injected in all frames.