I'm trying to write simple extension that would act on request headers.
In documentation there is something about chrome.WebRequest, but I have no idea how to make it work....
When I put listener to content page, chrome.WebRequest is undefined, when I put it to background section, totally nothing happens...
manifest
{
"manifest_version": 2,
"name": "RequestSpy",
"version": "0.1",
"description": "HTTP/S Request Analizer",
"background": [
{
"scripts": ["scripts.js"]
}
],
"icons":{
"128":"spy.png"
},
"permissions": [
"*://*/*","webRequest"
]
}
script.js
alert('haha');
chrome.webRequest.onHeadersReceived.addListener(function(details){
console.log(details);
alert('huhu');
});
Any help?
manifest.json
{
"name": "OnRequest",
"version": "1.0",
"description": "I can't has cheezburger!",
"permissions": ["webRequest",
"webRequestBlocking",
"http://*/*",
"https://*/*"],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
background.js
chrome.webRequest.onHeadersReceived.addListener(function(e){
alert("onHeadersReceived");},{urls: ["http://*/*", "https://*/*"]}, ["blocking"]
);
Related
I click the button in https://chrome://extensions and it loads my extension. However the image/logo of the extension is the default one instead of the one I provided:
manifest.js:
{
"name": "My App",
"version": "1.0.0",
"description": "My extension doesn't do anything yet!",
"manifest_version": 2,
"background": {
"persistent": false,
"scripts": ["js/clear_history.js"]
},
"icons": {
"48": "images/logo.svg",
"96": "images/logo.svg"
},
"browser_action": {
"default_icon": "images/logo.svg"
},
"options_ui": {
"page": "options.html",
"chrome_style": true
},
"permissions": ["history", "storage"],
"web_accessible_resources": ["logo.svg"]
}
Project directory:
How do I fix it?
EDIT:
I have a Chrome Extension project, the structure looks like this:
project/
dist/
index.html
manifest.json
When I go More Tools -> Extensions -> Load Unpacked Extensions
I choose the root of the project, and it works! But I can't figure out how it knows to load dist/index.html? The manifest.json file doesn't say anything about dist/index.html, so how does Chrome know how to load the extension?
I built this extension a few months ago, and now I can't figure out how it works lol.
the manifest.json file looks like this verbatim:
{
"manifest_version": 2,
"name": "Suman Generator",
"description": "This extension allows the user to generate test skeletons.",
"version": "1.223",
"browser_action": {
"default_icon": "icon.png"
},
"options_page": "options.html",
"options_ui": {
"page": "options.html",
"chrome_style": true
},
"devtools_page": "aspects/dev-tools/dist/suman-dev-tools.html",
"optional_permissions": [
"<all_urls>"
],
"permissions": [
"management",
"activeTab",
"webNavigation",
"storage",
"*://*/",
"http://*/",
"https://*/",
"background",
"browser",
"tabs",
"identity",
"identity.email",
"https://www.googleapis.com/",
"pageAction",
"notifications",
"clipboard",
"clipboardWrite",
"clipboardRead",
"unlimitedStorage",
"webRequest",
"userinfo",
"webRequestBlocking",
{
"socket": [
"tcp-connect:*:*"
]
}
],
"web_accessible_resources": [
"modal-iframe.html"
],
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"omnibox": {
"keyword": "suman:chrome"
},
"oauth2": {
"client_id": "5461307462-7geu9374.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/chromewebstore.readonly"
]
},
"key": "MIIBC57LwMgUdRxfY4I40oAiKy57o3tWF/A1BrTNY0nQIDAQAB",
"short_name": "Suman Short Name",
"offline_enabled": true,
"background": {
"page": "background.html",
"persistent": true
},
"content_scripts": [],
"content_security_policy": "script-src 'self' https://plus.google.com 'unsafe-inline' 'http' 'https' 'unsafe-eval' '*'; object-src '*';"
}
{
"name": "Supreme Bot",
"description": "Automate the checkout process for supremenewyork.com!",
"version": "1.0.3",
"manifest_version": 2,
"permissions": ["*://*/*"],
"content_scripts": [
{
"matches": ["*://*.supreme.com/*"],
"js": ["jquery.js", "supreme.js"]
}
],
"browser_action": {
"default_icon" : "icon-16.png",
"default_title": "Enable/Disable"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"icons": {
"16": "icon-16.png"
},
{ //this line is showing up as an error that says manifest is not valid json
//dictionary keys must be quoted
"name": "Supreme Bot",
...
"options_page": "options.html",
...
}
}
I am working on an autofill and auto-checkout bot for buying clothing. I am trying to add an options page so that I will be able to adjust sizes (code for that is in a different file). Line 25 column 6 says that there is a syntax error where dictionary keys must be quoted. Any ideas?
If you check the JSON sample here, that part after the comma should be followed by a "key" not a new pair of curly brackets. Try removing it so your JSON file looks like this:
{
"name": "Supreme Bot",
"description": "Automate the checkout process for supremenewyork.com!",
"version": "1.0.3",
"manifest_version": 2,
"permissions": ["*://*/*"],
"content_scripts": [
{
"matches": ["*://*.supreme.com/*"],
"js": ["jquery.js", "supreme.js"]
}
],
"browser_action": {
"default_icon" : "icon-16.png",
"default_title": "Enable/Disable"
},
"background": {
"scripts": ["background.js"],
"persistent": false
},
"icons": {
"16": "icon-16.png"
},
"name": "Supreme Bot",
"options_page": "options.html",
}
I made a chrome app to display my web by webview tag, but the js API alert()/confirm() doesn't work. That made me wondering. Chrome app needs to config something to support confirm?
this is my manifest.json:
{
"app": {
"background": {
"scripts": ["background.js"]
}
},
"manifest_version": 2,
"name": "Performance Monitor",
"version": "1.0",
"description": "A performance monitor to show cpu and memory status.",
"icons": {
"16": "img/ccloud.png",
"48": "img/ccloud.png",
"128": "img/ccloud.png"
},
"permissions": [
"webview"
],
"webview": {
"partitions": [
{
"name": "static",
"accessible_resources": ["header.html", "footer.html", "static.png"]
},
{
"name": "trusted*",
"accessible_resources": ["local_*.html", "*.png", "*.js"]
},
{
"name": "trusted-audio",
"accessible_resources": ["*.mp3"]
}
]
}
}
It seems as if my background.js is triggered every refresh [planted an alert, and i see it every refresh, also my context menu is duplicating its inner self].
this is my manifest file:
"manifest_version": 2,
"name": "test",
"description": "test",
"version": "1.0",
"permissions": [
"activeTab",
"storage",
"tabs",
"contextMenus",
"https://*/*",
"http://*/*",
"https://www.google.com/_/chrome/newtab*"
],
"browser_action": {
"default_icon": "raj_robot.png",
"default_title" : "MemoMi"
},
"chrome_url_overrides" : {
"newtab" : "mypage.html"
},
"background": {
"scripts" : ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js" : ["selection.js"],
"run_at": "document_end"
}
],
And this is my background script:
function handle_click() {
alert("hi there!");
}
chrome.contextMenus.create({
title: "menu title",
contexts:["selection"],
onclick: handle_click
});
what am I doing wrong here?
Thanks!
Gura
Ok, I found it. I was actually implicitly triggering background.js by using methods in the content scripts, that should have been in the background.js. Just comment out your code and and see if it improves.