This question is more for the benefit of others and my own curiosity, as I have synthesized a workaround for now (using "matches": ["http://*/*", "https://*/*"] and if (location.hostname == "www.youtube.com").
Anyway, when I have an issue like this I break the code down into simpler and simpler forms until it starts to work. Then I can figure out what's tripping up the code. But I've hit that point now where it can't get simpler and it still doesn't work. Chrome just won't inject a content script into any of YouTube's pages.
Files (link to ZIP of the following)
manifest.json:
{
"name": "test",
"version": "0",
"manifest_version": 2,
"content_scripts": [
{
"js": [
"test.js"
],
"matches": [
"*://youtube.com/*"
],
"run_at": "document_end",
"all_frames": true
}
]
}
test.js:
alert("test");
Progress
Doesn't work:
Varying the values and statically defining (no wildcards) the matches URL
Varying the values of run_at
Varying the values of all_frames
Varying the scripting in test.js
Fresh install of Chrome v24.0.1312.57 on a fresh install of Windows 7 x64
Does work:
Changing the matches value to ANYTHING other than YouTube
Changing the matches value to "http://*/*", "https://*/*"
I feel like I'm missing something really obvious here, but it's been days.. ;/
This works for me if you define the match in the manifest as "http://www.youtube.com/*"
Related
I have a chrome extension I have made and I want to convert it to Edge using the Microsoft Edge Extension Converter, everything works fine except for the popups tabs and cookies permissions
"content_scripts": [
{
"matches": [
"http://www.website.com/*"
],
"js": [
"jquery-3.1.1.min.js",
"startup.js",
],
"css": [
"font-awesome.css"
],
"run_at": "document_end",
"permissions": [
"cookies",
"tabs"
]
}
],
If i were to remove
"permissions": [
"cookies",
"tabs"
]
The extension will load however the communication between the popup and the window will not work, but if i leave the code in i get the following error
Manifest parsing error: Invalid field 'permissions' found in 'content_scripts'.
I try to check the documentation and find that permissions are not the part of content_scripts.
In your sample above, I can see that you are using permissions under content_scripts.
I think this is the cause for this issue.
As per the documentation, following keys can be used with content_scripts.
all_frames, css, exclude_globs, exclude_matches, include_globs, js, match_about_blank, matches, run_at
to get the example refer link below.
content_scripts
To solve the issue, you can try to put 'permissions' outside the 'content_scripts'.
Reference:
permissions
I'm trying to load an extension, which was originally developed for Chrome, into Firefox. I'm aware that there are subtle differences, my idea was to fix the errors one by one.
The manifest can actually be loaded, an icon is added and the extension is listed as installed.
But during the loading, there are two warnings. One of them is:
Reading manifest: Error processing content_scripts.0.permissions: An unexpected property was found in the WebExtension manifest.
Unfortunately, this doesn't tell me which property is unexpected. I opened the debug consoles, the message is identical, there is no additional information.
The content_scripts section from the manifest is this:
"content_scripts": [
{
"css": [
"extra.css",
"all.css",
"bootstrap.min.css"
],
"js": [
"firebase.js",
"jquery.min.js",
"content.js",
"popper.min.js",
"bootstrap.min.js"
],
"matches": [
"https://dlab.epfl.ch/*",
"https://*.wikipedia.org/*"
],
"permissions": [
"storage",
"activeTab"
]
}],
The permissions look good to me. I checked against the Mozilla docs here, to avoid something like a spelling mistake. But storage and activeTab are allowed as permissions.
How can I find out what this unexpected property is ?
For reference, here is the full manifest: https://pastebin.com/dkaNmZHk
As #wOxxOm said, it is a simple mistake in the JSON layout:
permissions should be top-level and not within content_scripts.
sorry if this has already been asked - I looked extensively, but can't find anything that seems to address it. Though it's quite possible it's been asked a dozen times already and the language used just went completely over my head. Which brings me to this: I'm not technologically stupid or anything, but as far as coding anything goes, that's another story entirely and I know virtually zero terminology regarding Chrome extensions. I just started googling about an hour ago.
Anyway, the question. I'm trying to make an extension to replace a single gif on a website I frequent. It's a loading image, so it appears on virtually every page, and it's just atrocious. The image is called (is that the right word?) by a script...rocket-script, I think it's called, which refers to it as ajax_loader, from browsing the page source? And the CSS stylesheet gave me the URL for the image.
So, here is the code I have, based on googling:
manifest.json
{
"manifest_version": 2,
"version": "1.0",
"name": "extensioname",
"description": "extensiondescription",
"content_scripts": [
{
"matches": ["websiteitselfurl.com*","URLofimagetobeblocked.gif"],
"js": ["part2.js"]
}
]
}
And then there's
part2.js
document.images[0].src = "replacementimage.gif";
document.images[0].height = "300";
document.images[0].width = "300";
Obviously those aren't the actual URLs, but...
All this ends up doing is replacing an image on every webpage, regardless of where it is, with the replacement gif. And not even the loading image in question on the site I am trying to replace in the first place.
I've tried changing the values in the "matches" line to a few different things, including at the end as in the example I found, and...that's literally all I can think to do.
I'd like to reiterate that I'm a complete know-nothing moron about this, so I apologize if it's already been asked, but I really cannot find an answer anywhere, and for the life of me I cannot get this to work myself and I'm out of ideas at this point. I registered here just to ask because I'm like ripping my hair out over it.
Any guidance whatsoever would be tremendously appreciated. Thank you!
Considering you are referring gif hosted in external site(imgur), you should use the full path of that image: https://i.imgur.com/Li7isRP.gif
manifest.json
{
"manifest_version": 2,
"version": "1.0",
"name": "extensioname",
"description": "extensiondescription",
"content_scripts": [
{
"matches": [
"http://websiteitselfurl.com/*", "https://websiteitselfurl.com/*"
],
"js": [
"content.js"
]
}
]
}
content.js
var ajax_loader = document.getElementById("ajax-loader");
ajax_loader.style.setProperty('background', 'url("https://i.imgur.com/Li7isRP.gif")', 'important');
// If needed, you could also change width/height of ajax_loader to better match the new image.
Just thought I would throw in another possible avenue for a solution. Since you want to replace a gif that loads in dynamically, it might be better to just redirect the request rather than try to alter the page after it is called. Something using the webRequest api would work well for this. For example:
manifest.json
{
"name": "VF Sample",
"version": "1.0.0",
"description": "A sample for VF gif replacement",
"manifest_version": 2,
"permissions": [
"webRequest","webRequestBlocking","http://vampirefreaks.com/*"
],
"background": {
"scripts": ["bgp.js"]
}
}
bgp.js
chrome.webRequest.onBeforeRequest.addListener(function(details){
return {redirectUrl:"http://i.imgur.com/Li7isRP.gif"};
},
{urls: ["http://vampirefreaks.com/_img/site/ajax-loader*"]},["blocking"]);
I have created a Chrome extension which contains two html pages the background.html and helper.html.
I am trying to inject code into the helper.html which runs of course inside the extension. helper.html runs as a popup window which I created with chrome.windows.create(object createData, function callback). However, so far I am unable to do so. From the documentation I understand that my Content Script rule should be
"content_scripts": [
{
"matches": ["chrome-extension://*/*"],
"js": ["jquery.js","myscript.js"],
"css": ["style.css"],
"run_at": "document_end"
}
but it fails.
Note that when I use localhost instead, for example
"content_scripts": [
{
"matches": ["http://localhost/"],
"js": ["jquery.js","myscript.js"],
"css": ["style.css"],
"run_at": "document_end"
}
it works. The localhost runs the exact same code but somehow the extension refuses to recognize the file I am trying to match ( "matches": ["chrome-extension://*/*"])
Chrome extensions can't inject content scripts into Chrome extensions.
You'll want to use message passing instead.
I'm having a problem controlling what pages my content scripts are injected into. The chrome extension developer guide specifies that I can use an "exclude_matches" directive in my manifest.json to exclude certain pages from injection.
However, this doesn't seem to have any effect. My content script still executes on pages that I have specified as ignored.
I have put the steps to reproduce in a Gist. The code is also available on Github.
Any ideas what I'm doing wrong?
manifest.json
{
"name": "Testing Extension",
"version": "1.0",
"description": "Test the chrome extensions exclude_matches.",
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"exclude_matches": ["http://news.ycombinator.com/"],
"js": ["content.js"]
}]
}
content.js
console.log("hello from the content script");
This is Bug #100106. exclude_matches do not function properly.
To solve the problem, use exclude_globs instead of exclude_matches.
Also, your exclude_matches rule does only match http://news.ycombinator.com/.
Suffice the pattern with an asterisk to match the whole site: http://news.ycombinator.com/*.
See also: Match patterns.