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.
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.
I have a very basic Chrome extension. I can execute JS just fine but accessing anything in the Chrome API seems to be an issue. I am trying remove cookies for a particular site. However, I get the following error when my code executes.
The error:
content.js:6 Uncaught TypeError: Cannot read property 'getAll' of undefined
My Code:
(function(){
chrome.cookies.getAll({}, cookies=>{
_.forEach(cookies, cookie=>{
chrome.cookies.remove({name: cookie.name, url: "www.mydomain.com"});
});
});
)();
I figured it may have something to do with my permissions but I am not sure. Here is my manifest.json file.
{
"manifest_version": 2,
"name": "Hello World Extension",
"version": "0.1",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jquery.js","content.js"]
}
],
"permissions": [
"cookies"
]
}
To use the cookies API, you must declare the "cookies" permission in your manifest, along with host permissions for any hosts whose cookies you want to access.
{
"manifest_version": 2,
"name": "Hello World Extension",
"version": "0.1",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["jquery.js","content.js"]
}
],
"permissions": [
"cookies",
"http://*/*",
"https://*/*"
]
}
To remove the cookies, try this:
function removeAll(url){
chrome.cookies.getAll({}, function(cookies) {
for (var i in cookies) {
chrome.cookies.remove({"url": url, "name": cookie.name});
}
});
}
I hope this works
I'm starting to create a simple chrome extension and one of the features I need is a notification system, so I'm using onesignal, in my script. I wish the user when installing the chrome extension to subscribe automaticlly, but it is not loading the object of onesignal which I can't figure out why. I'm saying this because no subscriptions is showing up after I install it.
My code:
manifest.json
{
"name": "My title",
"version": "0.0.1",
"manifest_version": 2,
"description": "some description",
"background": {
"scripts": [
"background.js","OneSignal.js"
],
"persistent": false
},
"browser_action": {
"default_title": "my extension"
},
"permissions": [
"https://*/*",
"http://*/*",
"tabs",
"gcm",
"notifications",
"storage",
"identity"
]
}
background.js:
OneSignal.init({appId: "dasdasd-b228-437d-bb8f-43asdasdb3", googleProjectNumber: "99999999"});
Am I missing something?
The problem is in the scripts order:
Solution:
...
background": {
"scripts": [
"OneSignal.js","background.js"
],
..
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/*"
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?