I'm currently making a Chrome extension that contains two different scripts. For some reason when I navigate in and out of a website listed explicitly in the matches property, the script will not function unless I refresh the page. Is there a way to get the script to load each time without needing to refresh the page?
Here is my manifest.json:
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["script.js"]
},
{
"matches": ["https://www.somewebsite/*"],
"js": ["script.js", "specificScript.js"]
}
]
Related
I'm working on an extension that injects some html code (display a modal) on a specific list of partner websites.
Because this list grows everyday, my extension fetch an external json file and compare it with the current website. If one of them matches, I show the modal.
I'm currently asking for a *://*/* permission for content_scripts.
I tried to set the list of websites in the manifest, but for each new version it needed the user to reactivate the extension as it required "new permissions".
Here is an extract of my current manifest.json
{
"permissions":["*://*/*","activeTab","storage","<all_urls>"],
...
"content_scripts": [
{
"run_at": "document_idle",
"matches": ["*://*/*"],
"css": ["..."],
"js": ["..."]
}
],
...
"externally_connectable": {
"matches": [
"*://localhost/*",
"*://*.mywebsite.com/*"
]
}
}
What would be the best permissions configuration to shorten the approval process? Currently each time I submit a new version it takes several days to be approved, even for small changes.
I'm writing a chrome extension, to do some modification to the page content, but I have to click on it to make it working on current page.
What I want is: if I click on the extension icon (to enable it), it will always enabled, no matter what new pages/tabs are open, and will work on them?
How to write code to configure it?
Using content script you can achieve this. Content scripts are files that run in the context of web pages so you can modify webpage content.
Add below code in manifest.json
{
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["your-content-script.js"]
}
],
"permissions": [
"tabs", "http://*/*","https://*/*"
]
}
To learn more, read this https://developer.chrome.com/extensions/overview.html#arch
I am trying to understand, what is the difference between:
"permissions": [
"*.google.com"
],
and
"content_scripts": [
{
"matches": ["*.google.com"]
}
]
1. Permissions for domains
Web pages can not make Cross-Origin XMLHttpRequest (AJAX), but extensions can. Adding the domain in permissions will allow you to do ajax requests to the specified domain from your content scripts.
2. Matches
Content scripts work inside loaded pages. With matches you are able to specify inside which pages you want to inject your content scripts.
Example: I want to fetch weather data from openweathermap.org, and present the data only on google.com pages.
"permissions": [
"http://api.openweathermap.org/*"
],
"content_scripts": [
{
"matches": ["https://*.google.com/*"],
"js": ["js/content.js"]
}
]
Let me explain. My chrome extension consists of this:
Injecting an html page in an iframe
Inside this html page is another iframe sourced to an external site
This external site is being modified by the extension also
The problem is I am not seeing the effects I should be. How do I specify I want to display the version of my site affected by the extension?
Edit: Here is the exact part of the code that Im working with:
<iframe id="wikiforum" src="http://mudandblood.net/html/modules.php?name=Forums"></iframe>
That url its currently pointing to is also having css and js injected into it by my extension. Everything works how it should when I visit the site directly, but through the iframe it remains unchanged. Thats what I'm trying to fix.
2nd Edit: Yes, I am injecting the content scripts through the manifest. Like so:
{
"name": "MnB2+",
"version": "1",
"manifest_version": 2,
"content_scripts": [
{
"js": ["contentscript.js"],
"matches": ["http://mudandblood.net/mudandblood2.swf","http://www.mudandblood.net/mudandblood2.swf"],
"all_frames": true
},
{
"css": ["style.css"],
"js": ["csforum.js"],
"matches": ["http://mudandblood.net/html/*"]
}
],
"permissions": [
"tabs"
],
"web_accessible_resources": [
"irc.html",
"wiki.html",
"style.css",
"vectors/*.svg"
]
}
So I'm a dolt and a noob, I solved my own problem. Downvote me as you will, I apologize sincerely. Wouldn't have figured it out though if I didn't post here.
The key was I didn't include "all_frames": true in the second content script section. Hope this at least helps another newbie on the way.
Have a google chrome extension that was working fine -but then v38.
"content_scripts":
[
{
"matches": [ "https://www.mydomain.com/*" ],
"run_at": "document_end",
"js": [ "cs_storage.js", "utils.js", "cs_utils.js", "content.js" ]
}
]
The problem is that for a specific page the document_end event doesn't trigger.
Used to work pre v38.
Once one that page - if I reload the page - then it triggers.
When one navigates to that page - there's a redirect and takes a little bit of time 2-3 seconds.
I did intercept the document_start event and that does trigger - but not document_end for this page.
Any help appreciated.