Pagemod: how to update the exclude list?

Hi,

i have a simple pagemod which applies on every domain:

var list = [];
var p = require("sdk/page-mod");
var pm = p.PageMod({include:"*", exclude:list, ... });

i created a context menu item where i add current domain to the exclude list and then i destroy the pagemod with pm.destroy(); and want to create it again, but that doesn’t work.

how can i instantly apply my updated exclude list?

I’m not sure why recreating it wouldn’t work. Can you show more of your code?

here it is, simplified… i tried once again from scratch and it stil doesn’t do anything after destroy() - the pagemod doesn’t exist and isn’t applied to any website anymore.

part 1:

var global_settings = {
    include:"*",
    exclude:[],
    contentStyleFile:d.url("css/common.css")
};

var global_mod = p.PageMod(global_settings);

part 2, context menu:

cm.Item({
    label:"Exclude this domain",
    context:cm.SelectorContext("*"),
    contentScript: 'self.on("click", function (node, data) {' +
                   '  self.postMessage(document.location.hostname);' +
                   '});',
    onMessage: function (domain) {
        console.log(domain);
        global_settings.exclude[global_settings.exclude.length] = domain;
        global_mod.destroy();
        global_mod = p.PageMod(global_settings);
    }
});

Two things I can think of (didn’t test), does global_mod exist after it’s destroyed? If not, then even if you did var global_mod it wouldn’t exist after the block it’s in is closed on the next line. Second, is p.PageMod itself changing?

it was my fault. or 2 of them. destroying part worked, everything else not.

  1. as you can see above, i forgot to set attachTo:[“existing”] when resetting it all, so it wasn’t applied immediately.
  2. when adding a domain to the list, i didn’t add prefix *. so it didn’t work properly.

thanks for looking into the issue!