Here's my manifest.json:
{
"manifest_version": 2,
"name": "Resource Blocker",
"description": "Blocks resources loading from websites.",
"version": "1.0",
"background": {
"scripts": ["main.js"]
},
"permissions": [
"tabs", "http://*/*", "https://*/*", "webRequest", "webRequestBlocking"
]
}
And here's main.js:
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {cancel: details.url.indexOf("://www.facebook.com/") != -1};
},
{urls: ["<all_urls>"]},
["blocking"]);
This is clearly blocking all requests to facebook.com. However, I want to block requests to all websites. I tried replacing ://facebook.com/ with <all_urls> and ://*/* to no avail. Does anyone know the solution?
Related
I tried the code from this SO to block certain websites:
manifest.json:
{
"name": "StudyBuddy",
"description": "Helps you study by blocking distracting websites",
"version": "2.0",
"permissions": [
"webRequestBlocking",
"webRequest",
"activeTab",
"tabs",
"http://*/*",
"https://*/*"
],
"background" : {
"scripts": [
"background.js",
"persistent": true
]
},
"manifest_version": 2
}
Background.js:
console.log("Loaded extension");
function blockRequest(details) {
return {cancel: true};
}
function updateFilters(urls) {
if(chrome.webRequest.onBeforeRequest.hasListener(blockRequest))
chrome.webRequest.onBeforeRequest.removeListener(blockRequest);
chrome.webRequest.onBeforeRequest.addListener(blockRequest, {urls: ["*://blank.org/"] }, ['blocking']);
}
updateFilters();
I don't get any error but I can easily access blank.org despite the code.
Even after searching a lot of topics in stack overflow, nothing helped me to fix this error...
I'm trying to create an extension, and for now there are simple codes in it, but unfortunately, the console is not logging 'Hello, world!' from the content_scripts file.
manifest.json
{
"manifest_version": 2,
"name": "Example",
"shortname": "exmpl",
"description": "__MSG_appDesc__",
"version": "0.0.1",
"default_locale": "en",
"author": "Mateus Akino",
"icons": {
"16": "i16x.png",
"48": "i48x.png",
"128": "i128x.png"
},
"homepage_url": "http://example.com/",
"browser_action": {
"default_icon": "i32x.png",
"default_popup": "popup.html"
},
"update_url": "http://example.com/update.xml",
"chrome_url_overrides": {
"newtab": "newtab.html"
},
"content_scripts": [{
"matches": ["*://*.youtube.com/*"],
"js": ["execute.js"],
"run_at": "document_end"
}],
"background": {
"scripts": ["background.js"]
},
"permissions": [
"activeTab", "tabs", "i18n", "management", "webNavigation", "<all_urls>"
]
}
execute.js
console.log("Hello, world!");
background.js
chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) {
chrome.tabs.executeScript(null, {
file: "execute.js"
});
});
I fixed the problem, so I'm posting it here if someone else has the same issue.
Looks like the code was fine, the problem was the way I was loading the extension...
As I'm using 'Load unpacked extension', my manifest.json wasn't updating just by disabling and enabling it (neither by using Refresh extensions now).
So I removed the extension, loaded it again and it's working normally now.
I built a Chrome Extension script that is supposed to run on Reddit.
My script:
console.log("hello world");
My manifest.json
{
"manifest_version": 2,
"name": "Name",
"description": "Desc",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": [
"*://reddit.com/*"
],
"js": [
"contentscript.js"
],
"run_at": "document_end"
}
],
"permissions": [
"tabs", "*://reddit.com/*", "activeTab"
]
}
The script doesn't show up in the "Content Script" section in the chrome dev tools. Does anyone have an idea why my extension is not running?
"*://reddit.com/*" doesn't match a valid url, you should use "*://*.reddit.com/*"
I have this code below that until last week was working, but now when I will go execute again, this not works.
Based in this question and tested by me, using chrome.tabs.onUpdated.addListener event, works fine, but I have some strings in msgBox.js file, that cause errors relative to encoding (UTF-8/ANSI) and because this, all script inside of msgBox.js file is necessary execute using chrome.tabs.executeScript.
msgBox.js
function msg()
{
alert("hello!");
}
msg();
event.js
chrome.webRequest.onCompleted.addListener(
function onWindowLoad() {
chrome.tabs.executeScript(null, {
file: "msgBox.js"
}, function() {
});
}
,
{
urls: ["<all_urls>"],
types: ["main_frame"]
},
["responseHeaders"]
);
manifest.json
{
"background": {
// "page": "popup.html"
"scripts": ["event.js"]
},
"description": "Media Player for Flash",
"manifest_version": 2,
"name": "Media Player",
"icons": {
"128" : "picture/flash128.png" ,
"48" : "picture/flash48.png"
},
"web_accessible_resources": [
"event.js"
],
"content_scripts": [
{
"matches": ["<all_urls>", "*://*/*", "http://*/*", "https://*/*"],
"js": ["event.js"],
"run_at": "document_end",
"all_frames": true
}
],
"permissions": [ "tabs", "background", "activeTab", "<all_urls>", "webNavigation", "webRequest", "http://*/*", "https://*/*", "*://*/*" ],
"version": "1.0"
}
What can is wrong?
Any help will welcome.
According to https://developer.chrome.com/extensions/tabs#method-executeScript
null is not a valid option for object in "executeScript", Try using "string" in it's place. It worked for me at least when trying to reproduce and fix
Edit: although that does not explain why it worked before but stopped
I am trying to load and run a very basic extension that blocks all URLs but nothing happens.
The MANIFEST.JSON file:
{
"manifest_version": 2,
"name": "Dial2Action",
"description": "This is my description",
"version": "1.0",
"background": {"scripts":["background.js"]},
"permissions": [
"webRequest",
"webRequestBlocking",
"https://app.dial2web.com/"
]
}
and the background.js file:
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return {cancel: true}; },
{urls: ["<all_urls>"]},
["blocking"]);
I will be glad to get a hint or a reference to a working simple redirect extension.
That's because you have only the block permission for "https://app.dial2web.com/".
You need the permission for all urls:
{
"manifest_version": 2,
// other stuff
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>"
]
}
This works fine for me.