Chrome extension content_scripts v38 - google-chrome-extension

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.

Related

How can I inject CSS before content script is loaded in Chrome Extension MV2?

I am trying to use user-session recording tools (like FullStory or Livesession) in my Chrome Extension.
The way those tools work is that during the session capture, they make a copy of the page CSS to recreate the playback in the future.
The problem is that they don't collect my content script's injected CSS file:
"content_scripts": [
{
"matches": [...],
"js": [
"build/content.js"
],
"css": [
"build/content.css"
]
}
],
so the recording output is all messed up and broken.
I thought that it may be due to the CSS being injected after the JS is executed but I don't think this is the case according to this article.
How can I make it work?

Automatically load script for website match without needing to reload

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"]
}
]

What permissions should I request to display a modal on a specific list of websites and have a short approval delay

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.

How to make write a chrome extension which is always enabled for any urls?

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

How to link to the extension-affected version of a page from within an iframe?

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.

Resources