My extension is simply performing actions on pages based on user clicks; it works fine on all websites except for Gmail.
Here's my manifest file:
{
"name": "My Extension",
"version": "2.0",
"description": "description.",
"permissions": [
"tabs"
],
"icons": {
"16" : "images/icon-16.png",
"48" : "images/icon-48.png",
"128" : "images/icon-128.png"
},
"background_page": "background.html",
"options_page": "Options.html",
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["css/style.css"],
"js": ["inject.js"]
}
]
}
When I click on a web page, my inject.js normally fires an alert() -- it handles onclick events. But, on Gmail pages, it does not catch the click event.
Gmail is composed of frames. By default, content scripts are only injected at the top-level frame. Add "all_frames":true to the manifest, so that the content script is also injected in the frames.
"content_scripts": [{
"matches": ["<all_urls>"],
"css": ["css/style.css"],
"js": ["inject.js"],
"all_frames": true
}]
Related
My extension doesn't run at document_start. The manifest.json:
{
"manifest_version": 3,
"name": "Lift Web Restrictions",
"description": "Simple extension that removes most ads, web restrictions, adds mods to MooMoo.io / Krunker.io / and more!",
"version": "0.0.5",
"icons": {
"16": "logo/sw16.png",
"48": "logo/sw48.png",
"128": "logo/sw128.png"
},
"permissions": [],
"host_permissions": [
"*://*/*"
],
"background": {
"service_worker": "service-worker.js"
},
"web_accessible_resources": [
{
"resources": ["modules/script.js"],
"matches": ["*://*/*"]
}
],
"content_scripts": [{
"js": [
"modules/transfer.js"
],
"matches": ["http://*/*", "https://*/*"],
"all_frames": true,
"run-at": "document_start"
}]
}
There's a console.log within modules/transfer.js, however the page's script tag beats it.
Launching egAps
index.bf049c93.js?52f6f7bb66295262766e:2 Downloading d.js...
index.bf049c93.js?52f6f7bb66295262766e:2 Loading WASM c66eb3cbd8fdc1325900.wasm
^^^^ logged before script runs
index.bf049c93.js?52f6f7bb66295262766e:2 1 dependencies left
transfer.js:1 fireAt <--- where it runs
index.bf049c93.js?52f6f7bb66295262766e:2 0 dependencies left
index.bf049c93.js?52f6f7bb66295262766e:2 Running...
index.bf049c93.js?52f6f7bb66295262766e:2
Replace run-at with run_at
Thank you wOxxOm
I am developing an extension for Brave/Chrome and when I click the puzzle icon in the top right corner next to the row of pinned extensions, my extension is separated from the rest at the top with the label "These extensions can see and change information on this site". I'm not sure why. Here is my manifest.json.
{
"manifest_version": 3,
"name": "Extension Name",
"version": "1.0.0",
"icons": {
"512": "src/logo.png"
},
"action": {
"default_title": "Extension Name",
"default_popup": "popup.html"
},
"permissions": ["storage"],
"background": {
"service_worker": "src/bg.js",
"type": "module"
},
"content_scripts": [
{
"js": ["src/content.js"],
"matches": ["<all_urls>"],
"run_at": "document_start",
"all_frames": true
}
],
"web_accessible_resources": [
{
"resources": ["src/popup2.html", "src/script2.js"],
"matches": ["<all_urls>"]
}
]
}
My only permission is for storage. How do I make my extension not be labeled as having access to "see and change information on this site"?
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 am trying to develop my first extension in google chrome and I am following this tutorial: Tutorial
Everything is working great except the 2 lines of code in content.js
The problem is that the contents of "content.js" are not correct and I am getting "undefined" in chrome console for line 2.
Can someone please help me out and let me know why this happens?
I share the contents of content.js with you in order to help me out.
content.js contents:
var firstHref = $("a[href^='http']").eq(0).attr("href");
console.log(firstHref);
manifest/json file contents:
{
"manifest_version": 2,
"name": "My Cool Extension",
"version": "0.2",
"icons": { "128": "icon_128.png" },
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jquery-2.1.3.min.js", "content.js"]
}
],
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"tabs"
]
}
I guess, your content script is loading before the whole document is loaded.That's why it returned undefined.
To make sure your content scripts are inject at properly, you should define "run_at" in file manifest.json
Example:
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"],
"run_at": "document_end",
"all_frames": true
}
],
please check Content Scripts parameters for more details.
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.