Content script event listener not working in all tabs? (Firefox add-on SDK) -


in firefox sdk add-on, have simple content script adds keydown event listener page , logs event:

//content-script.js console.log("running"); window.addeventlistener("keydown", function(event) {   console.log("key down event"); }); window.focus(); 

and have written function set behavior in main.js:

//main.js function setuptab(tab) {   console.log("setup");   tab.attach({     contentscriptfile: "./content-script.js"   }); }  tabs.on("open", function(tab) {   setuptab(tab); }); setuptab(tabs.activetab); 

my ultimate goal run content script on tabs open when add-on starts up, tabs open afterward. moment running on active tab , subsequently opened ones.

when run add-on, console logs "setup" , "running" , logs key presses make in initial window, expected behavior. however, when open new tabs, first new tab opened log both "setup" , "running" not log keypresses. every new tab after log "setup", "running", , keypresses.

i have noticed add-on sdk version of firefox runs fresh installation each time, , first new tab opened (and tab) pops "what page?" message. might interfering somehow, if don't know how circumvent it.

i'm suspecting behaviour want @ every active tab. code may this:

//main.js var tabs = require("sdk/tabs");     tabs.on('ready', function (tab) {     tabs.activetab.attach({       contentscriptfile: "./content-script.js"     }) }); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -