How to read all http requests in Chrome Extension? - javascript

I want my Chrome Extension to read and display all http requests in alerts. But alerts are not displaying, console is clear with no errors. Here is my code:
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
alert(JSON.stringify(details));
},
{urls: ["<all_urls>"]},
["blocking", "requestBody"]
);
Also my manifest:
{
"manifest_version": 2,
"name": "Some_Name",
"version": "1.2",
"content_scripts": [{"matches": ["<all_urls>","http://*/*", "https://*/*"],"js": ["background.js"]}],
"background": {
"page": "background.html"
},
"permissions": [
"alarms",
"webRequest",
"webRequestBlocking"
],
"browser_action": {
"default_title": "Some extension"
},
"icons": {
"128": "icon.png" }
}

Related

No output to service worker console with chrome extension

I'm trying to build an extension to monitor the xhr portion of the devtools network tab. I decided to start as simple as possible with the background script below. I'm seeing no errors on loading the extension, but don't see any output in the console.
manifest.json:
{
"manifest_version": 3,
"version": "1.0",
"name": "Hello World!",
"description": "Learning how to make a chrome extension!",
"icons": {
"16": "images/puppy16.png",
"48": "images/puppy48.png",
"128": "images/puppy128.png"
},
"action": {
"default_icon": "images/puppy.png",
"default_popup": "popup.html"
},
"background": {
"service_worker": "background.js"
},
"host_permissions": [
"https://cnn.com/*"
],
"permissions": [
"webRequest"
]
}
In my background.js:
(function () {
chrome.webRequest.onCompleted.addListener(
function (details) {
console.log('HELLO THERE!!!!', details);
},
{ urls: ["<all_urls>"] }
);
}());
What am I doing wrong?

Chrome Extension, chrome.notification not work

We're developing a web extension. We're actually trying to add some functionalities on the extension such as notifications.
For instance, we don't see any notifications at all, not even in the log console and we can't figure out the problem.
Do you have any ideas ?
Here is our manifest and our background.
Thank you in advance.
{
"description": "truc écolo",
"manifest_version": 2,
"name": "PolNum",
"version": "0.1",
"icons": {
"48": "icons/icon48.png"
},
"permissions": [
"webRequest",
"activeTab",
"http://*/*",
"https://*/*",
"tabs",
"*://*.google.com/",
"storage",
"alarms",
"history",
"notifications"
],
"browser_action": {
"default_popup" :"popup.html",
"default_icon": {
"16": "icons/icon16.png",
"32": "icons/icon32.png"
}
},
"background": {
"scripts": ["background.js"]
}
}
chrome.notifications.create('test', {
type: 'basic',
iconUrl: "icons/icon16N.png",
title: 'Test Message',
message: 'You are awesome!',
priority: 2
});

Problem deploying Safari web extension to Mac App store

I have followed the steps to deploy the safari extension to mac app store by creating an archive and then validating it. I received no error when validating. However when trying to "Distribute App" The following error is coming up in the last stage. -"Corrupted manifest file. The manifest.json file could not be read in Safari extension bundle"
The extension build is running as per expectations locally.
Please help
My manifest.json
{
"author": "Author Name",
"background": {
"page": "index.html",
},
"version" : "1.0",
"browser_action": {
"default_icon": "assets/img/logo-64-disabled.png",
"default_title": "Title"
},
"content_scripts": [
{
"js": ["assets/js/index.js", "assets/js/content.js"],
"matches": ["<all_urls>"]
}
],
"content_security_policy": "script-src 'self' https://cdnjs.cloudflare.com; object-src 'self'",
"default_locale": "en",
"description": "Description",
"homepage_url": "https://example.com",
"icons": {
"128": "assets/img/logo-128.png",
"16": "assets/img/logo-16.png",
"32": "assets/img/logo-32.png",
"48": "assets/img/logo-64.png",
"64": "assets/img/logo-64.png"
},
"manifest_version": 2,
"name": "Name",
"options_ui": {
"open_in_tab": false,
"page": "assets/options.html"
},
"permissions": [
"contextMenus",
"tabs",
"activeTab",
"webNavigation",
"storage",
"<all_urls>",
],
"short_name": "Name",
"web_accessible_resources": ["assets/*"]
}

How do I make a button that executes the background.js in a chrome extension?

I am making a chrome extension. Here is the code:
Manifest.json:
{
"name": "My name!",
"version": "2.0",
"description": "Blocks ads",
"permissions": ["webRequest", "webRequestBlocking", "<all_urls>"],
"browser_action": {
"default_icon": "shield.ico",
"default_popup": "popup.html",
"default_title": "Ad be gone"
},
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
background.js:
chrome.webRequest.onBeforeRequest.addListener(
function(details) { return {cancel: true}; },
{ urls: ["*://*.doubleclick.net/*", "*://*.ads.google.com/*",] },
["blocking"]
);
How would I make a button in popup.html that turns on and off the background.js and alerts the user that it is doing so? I basically want to make a button that turns on and off the ad blocker.

Chrome extension Web Request doesn't show info

I was looking for without success.
I want to get the status of my requests from my extension but I can not get it.
Manifiest
{
"manifest_version": 2,
"name": "Pixel Checker TT",
"description": "This extension validate your pixels and its requests",
"version": "1.6",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"background": {
"persistent": true,
"scripts": ["popup.js"]
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["sources/js/jquery-3.0.0.min.js","content.js"]
}
],
"permissions": [
"tabs",
"activeTab",
"webRequest",
"webRequestBlocking",
"*://*.mydomain.co/",
"*://*.myotherdomain.co/"
]
}
popup.js or background code
chrome.webRequest.onCompleted.addListener(function(details) {
for (var i = 0; i < details.requestHeaders.length; ++i) {
console.log(details.requestHeaders[i].url);
console.log(details.requestHeaders[i].statusCode);
}
},
{urls: ["<all_urls>"]},
['blocking','requestHeaders']);
The problem is that I dont have errors just aren not printed the info. I also tried to put the info in a div with $('#pixelsFound').text(details.requestHeaders[i].url)
but doesn't work too.

Categories