So basically I need to do a couple of things
chrome.webrequests.onBeforeRequest.addlisteners
chrome.browser.addbadgetext
chrome.tabs.query
in a content script. The reason why I want this in content script is because I want the above to trigger without clicking the extension icon on the active page. How can I do that?
Below is my manifest.json
{
"manifest_version": 2,
"name": "My Ext",
"description": "My Ext desc",
"icons": {
"16":"logo-sm.png",
"48":"logo-sm.png",
"128":"logo-sm.png"
},
"version": "1.0",
"homepage_url": "abc.com",
"browser_action": {
"default_icon": "favicon.png",
"default_title": "My ext"
},
"background": {
"scripts": ["scripts/background.js"],
"persistent": true
},
"web_accessible_resources": ["oxy-logo-sm.png"],
"content_scripts": [{
"matches": ["<all_urls>"],
"all_frames": true,
"js":["scripts/content.js"],
"run_at": "document_start"
}],
"permissions": ["activeTab", "webRequest", "tabs", "<all_urls>"]
}
Related
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"?
I've written an add-on / extension for the Tor browser. As we know, Tor is equivalent to Firefox. So, the extension I created works like a charm in Firefox, but in Tor, not so good.
So, this is what I'm trying to do inside the background script:
chrome.windows.create({
url: `popup.html`,
type: 'popup',
height: 800,
width: 900
});
In Tor, the popup is opened, but remains black/empty, nothing is happening inside the window
Here is my manifest.json
{
"name": "Tor test",
"version": "0.0.0",
"description": "Extension",
"manifest_version": 2,
"permissions": [
"background",
"storage",
"unlimitedStorage",
"*://*/*"
],
"browser_action": {
"default_icon": "icon-off-128.png"
},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"run_at": "document_idle",
"js": ["content.js"]
}
],
"web_accessible_resources": [
"popup.html"
],
}
Any suggestions why the popup doesn't display any content inside that popup?
I have this very simple manifest.json:
{
"manifest_version": 2,
"name": "Sample Name",
"version": "1.0.0",
"description": "This is a sample description",
"short_name": "Short Sample Name",
"permissions": ["tabs", "https://google.com/*", "activeTab", "declarativeContent", "storage"],
"content_scripts": [
{
"matches": ["https://www.google.com/*"],
"js": [
"background.js",
"test.js"
],
"css": ["test.css"]
}
],
"browser_action": {
"default_title": "This is a sample title",
"default_popup": "popup.html",
"default_icon": {
"16": "icons/icon16.png",
"32": "icons/icon32.png"
}
}
}
When I go to url https://www.google.com/ and open the content scripts tab in Chrome's dev's tools, I do not see my test.js and test.css scripts there. And, of course, they're not working in the page.
What should I do to add them and make them work?
P.S. Of course, I've created other files, such as window.html, popup.html, background.js, and test.js and test.css too.
The extension was installed successfully, for I see it in the list of my extensions...
I'm using several constants that are shared between my content.js and popup.js. How can I put them in one file and share them between both?
This does not work, global.js contains the constants
{
"manifest_version": 2,
"name": "Test Extension",
"version": "0.0",
"background": {
"persistent": false,
"scripts": ["global.js", "background.js"]
},
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["global.js", "content.js"],
"run_at": "document_end"
}],
"browser_action": {
"default_title": "Test Extension",
"default_popup": "popup.html"
},
"permissions": [
"activeTab"
]
}
global.js
var TEST = "test"
content.js/popup.js:
console.log(TEST)
in popup.js it prints TEST is not defined
You still need to add <script type="text/javascript" src="global.js"></script> to the HTML file. I thought it was included by default when you specify it in the manifest.json
In my content script I do
chrome.windows.create({url: "local.html", type: "popup"});
however, no window ever shows up.
Do I need to change my manifest file first? Why doesn't this function create a new window ever?
I have tabs enabled like so
{
"name": "Tool",
"version": "0.0.1",
"manifest_version": 2,
"description": "",
"homepage_url": "",
"icons": {
"16": "icons/on.png",
"48": "icons/on.png",
"128": "icons/on.png"
},
"default_locale": "en",
"background": {
"page": "src/bg/background.html",
"persistent": true
},
"browser_action": {
"default_icon": "icons/on.png",
"default_title": "browser action demo"
},
"permissions": [
"<all_urls>","tabs", "webNavigation"
],
"content_scripts": [
{
"run_at": "document_end",
"matches": [
"<all_urls>"
],
"js": [
"src/lib/jquery.min.js", "src/inject/inject.js"
],
"css": [
"src/inject/inject.css"
]
}
]
}
You are trying to call this from the content script.
Quoting the docs:
However, content scripts have some limitations. They cannot:
Use chrome.* APIs (except for parts of chrome.extension)
If you need to initiate some action that uses Chrome API from the content script, you have to message your background script to do this. See Architecture overview and Messaging.