manifest.json matches <all_urls> not working after publishing? - google-chrome-extension

From my extension's manifest.json file I am using this:
"content_scripts": [ {
"all_frames": true,
"js": [ "jquery-2.2.3.min.js", "content_script.js" ],
"matches": [ "<all_urls>" ],
"run_at": "document_start"
} ],
When I install my extension locally the matches: is set to all_urls and everything works as expected. My content_script is injected for locally opened file:///c:...whatever.html files which is what I want.
When I publish my app to the Chrome Store and install my extension it does not work anymore. Upon closer inspection I see the Google store has somehow tried to escape my all_urls and my manifest.json is now:
"content_scripts": [ {
"all_frames": true,
"js": [ "jquery-2.2.3.min.js", "content_script.js" ],
"matches": [ "\u003Call_urls>" ],
"run_at": "document_start"
} ],
Why? this completely breaks my extension. How does someone specify all_urls then? I have no idea what I'm doing wrong or why this is happening and appreciate any help someone can provide.

Related

Chrome extension manifest v3 exclude_glob and exclude_matches not working

I've got 2 scripts that I want to load depending on what site ppl open in browser ...
login.js should only be loaded on admin.someDomain.com, admin.someOtherDomain.com and localhost
dc_ctre_content.js should be loaded on all other pages opened in browser.
Now, login.js is correctly added, but dc_ctre_content.js is also added to admin.someDomain.com, admin.someOtherDomain.com and localhost domains and it shouldn't be!
Since I'm developing locally my local address is "http://localhost:5090/something" maybe that's the problem.
from manifest.json v3:
"content_scripts": [
{
"matches": ["*://admin.someDomain.com/*","*://admin.someOtherDomain.com/*","*://localhost/*"],
"js": ["js/login.js"],
"run_at": "document_end"
},
{
"exclude_globs": ["*://admin.someDomain.com/*","*://admin.someOtherDomain.com/*","*://localhost/*"],
"matches": ["https://*/*","http://*/*"],
"js": ["js/dc_ctre_content.js"],
"run_at": "document_end"
}
],
I've also tried with exclude_matches but no joy.
Any help appreciated on how to not load dc_ctre_content.js script on excluded domains.
Regards
this fixed it
"exclude_globs": ["http://localhost:*/*"]
I had to put :* after host name for this to work properly.

Content script pattern "*://mail.google.com/*" doesn't match gmail when using firefox

I have an extension that I've written for chrome. I recently decided I wanted to port it over to firefox, and I was surprised on how many things worked out of the box with no changes at all. However, one thing that has tripped me up is that for some reason my gmail.js content script is not being loaded. This is my content script:
{
"name": "Copy Machine",
"description": "Copies text more better",
"version": "0.6",
"permissions": ["contextMenus", "tabs"],
"icons": {
"16": "icon_16.png",
"32": "icon_32.png"
},
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2,
"content_scripts": [
{
"matches": [
"*://mail.google.com/*"
],
"js": ["gmail.js"],
"run_at": "document_idle"
},
{
"matches": [
"<all_urls>"
],
"js": ["generic.js"],
"run_at": "document_idle"
}
]
}
The first line of my gmail.js content script is:
console.log("GMAIL SCRIPT IS RUNNING");
And the first line of my generic.js content script is:
console.log("GENERIC SCRIPT IS RUNNING");
When I open my gmail account in firefox, in the console I see "GENERIC SCRIPT IS RUNNING", but not "GMAIL SCRIPT IS RUNNING."
With google chrome, this works as I would expect, but for some reason the URL pattern isn't matching. Is there something I am missing? Thanks.
So I ended up adding "*://mail.google.com/*" to the permissions in the manifest file, and that got things working the way I expected. I then had to fix a few other bugs with apis that were not available, this is what I should have started with:
https://extensionworkshop.com/documentation/develop/porting-a-google-chrome-extension/
I then went back to file a bug report, and when I remove "*://mail.google.com/*" it's continues to work. So maybe there's some weird circular dependency thing going on? I'm not sure.

Renaming content_script stops it from running in Chrome Extension

In my manifest.json I have:
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["js/punycode.js", "js/content-main.js"]
}
],
However if I rename the content-main.js to content-main1.js update the manifest.json to reflect the change ("js/content-main1.js") and reload the extension the script no longer runs.
How is this possible? Thanks
The Reload Extensions extension that I was using wasn't reflecting the changes in the directory.

How to get body.scrollHeight in script injected of Chrome Extension?

Here are the list of my project's files.
index.html - main extension file
manifest.json
background.html
background.js
content.js
manifest.json
manifest.json
...
"content_scripts": [
{
"all_frames": false,
"js": [
"content.js"
],
"matches": [
"https://www.****.com/vsearch/*"
],
"run_at": "document_end"
}
]
content.js
...
console.log(document.body.scrollHeight);
I need to get scrollHeight of special site in content.js.
But when I load this extension, sometimes I got scrollHeight of index.html.
By watching content.js using Chrome Dev Tool, content.js injected correctly in special site.
How can I fix this issue?

Chrome extension content script not injected to iframes

Our manifest.json contains:
"content_scripts": [
{
"js": [ "content-script.js" ],
"run_at": "document_idle",
"matches": ["https://*.example.com/*"]
}
],
Content script gets correctly injected to our pages at example.com unless somebody embeds our page to iframe on his page. Is there a way for our extension to inject content script to all iframes pointing to example.com if we want to keep "matches": ["https://*.example.com/*"]? We know it is possible with "matches": ["https://*/*"], "all_frames": true but we don't want to ask for wider permissions.

Resources