0

We are a group of students, and we are attempting to develop a web extension (chrome) for a project. We'd like to develop a web extension which measures the data usage of the Internet browser. To this goal, we want to take the header of a page to have files sizes.

We wanted to test if we could make an alert after receiving the headers.

We have make this test :

var callback = function(details) {
    console.log('Les Headers ont ete recus');
    alert("BBBBBBBBBBBBBBBBBBBBB");
}
var filter = { urls: 
    [
        '<all_urls>'
    ]
};
var opt_extraInfoSpec = [];

chrome.webRequest.onHeadersReceived.addListener(
    callback, filter, opt_extraInfoSpec
);

We also try this :

function callback() {
    console.log('Les Headers ont ete recus');
    alert("BBBBBBBBBBBBBBBBBBBBB");
}
var filter = { urls: 
    [
        '<all_urls>'
    ]
};
var opt_extraInfoSpec = ["requestHeaders"];

chrome.webRequest.onHeadersReceived.addListener(
    callback, filter, opt_extraInfoSpec
)

the manifest :

{

  "description": "truc écolo",
  "manifest_version": 2,
  "name": "PolNum",
  "version": "0.1",
  "icons": {
    "48": "icons/icon48.png"
  },
  


  "permissions": [
    "activeTab",
    "http://*/*",
    "https://*/*",
    "tabs", 
    "notifications",
    "webRequest",
    "*://*.google.com/",
    "storage"
  ],

"browser_action": {
    "default_popup" :"popup.html",
    "default_icon": {
      "16": "icons/icon16.png",
      "32": "icons/icon32.png"
    },
    "background": {
      "scripts": ["background.js"]
    }
  
    
  }

}

We are a beginner in Javascript

But we have a problem, we never see the alert and the console.log. Can we help us ?

Ostrale
  • 29
  • 6
  • 1. opt_extraInfoSpec = ['responseHeaders'] 2. [How to see background.js console?](/a/10258029), 3. move `background` section one level up in manifest.json, currently it's nested inside browser_action. – wOxxOm Oct 05 '21 at 17:46
  • @wOxxOm Thank you very much, you are really helping us a lot, it was pretty stupid, but we had some difficulties. Thanks again – Ostrale Oct 05 '21 at 20:10

1 Answers1

0

manifest.json :

{

  "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",
  "notifications" 
],

"browser_action": {
  "default_popup" :"popup.html",
  "default_icon": {
    "16": "icons/icon16.png",
    "32": "icons/icon32.png"
    }
  },

"background": {
  "scripts": ["background.js"]
  }  
}

background.js :

var callback = function(details) {
    console.log('Les Headers ont ete recus');
}
var filter = { urls: ['<all_urls>']
};
var opt_extraInfoSpec = ['responseHeaders'];

chrome.webRequest.onHeadersReceived.addListener(
    callback, filter, opt_extraInfoSpec
);
Ostrale
  • 29
  • 6