0

Here is the manifest file

{
"description": "",
    "manifest_version": 2,
    "name": "A",
    "version": "0.2.0.2",

    "permissions": [
        "activeTab",     
        "contextMenus",
        "tabs"
    ],

    "icons": {
        "48": "icons/48.png",
        "96": "icons/96.png"

    },


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

The mouseWheel.js file is:

window.addEventListener('DOMMouseScroll', mouseWheel);
function mouseWheel(e) {
console.log("Scroll capture Working");
}

Whenever I scroll at any page, it should print Scroll capture Working. But there is no response.

Aakash Gupta
  • 183
  • 1
  • 10

1 Answers1

1

Your script is executing in a background page: an invisible tab with its own document (and its own console).

So, when you attach to window events, they are events in that (invisible) tab, not actual browser tabs.

Go read the architecture overview. It will explain that you need to switch to Content Scripts if you need to interact with content in "real" tabs. Read that documentation thoroughly, but as a quickstart, this will give you what you want (in the manifest):

"content_scripts" : [{
  "matches" : ["<all_urls>"],
  "js" : ["mouseWheel.js"]
}],
Xan
  • 74,770
  • 16
  • 179
  • 206