Firefox SDK page-mod not working

2020-03-26 11:36发布

I have installed the following extensions: EPUBReader and Google Translator. The latter is built using Firefox SDK and originally has a page-mod include: ["*"] so it works only on http and https URLs. I modified the line into include: ["*","file://*","about:*"] so that it can also work with local files and "about:" links.

The reason i added "about:*" is because i want this extension to words on epub books that i read with EPUBReader. EPUBReader produces a URL something like this "about:epubreader?id=5". The problem is, Google Translator still won't translate anything when i double click on the words. It is interesting because whenever i try and open a fake "about:" URL that looks like "about:whatever", it works. I mean, you can double click on any word in the error page and it will translate.

I am pasting here the page-mod code snippet:

var workers = [], content_script_arr = [];
pageMod.PageMod({ /* page */
  include: ["*","file://*","about:*"],
  contentScriptFile: [data.url("content_script/inject.js")],
  contentScriptWhen: "ready",
  contentStyleFile : data.url("content_script/inject.css"),
  onAttach: function(worker) {
    array.add(workers, worker);
    worker.on('pageshow', function() { array.add(workers, this); });
    worker.on('pagehide', function() { array.remove(workers, this); });
    worker.on('detach', function() { array.remove(workers, this); });
    content_script_arr.forEach(function (arr) {
      worker.port.on(arr[0], arr[1]);
    });
  }
});

Help anyone??

1条回答
干净又极端
2楼-- · 2020-03-26 12:06

You can start with

include: /.*/,

which adds the page-mod to every single URL, and see if the culprit is in the include. If that fixed the problem, you can narrow it down even further.

It should fix the problem, because "*" only matches http, ftp and https URLS. See https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/util_match-pattern#Wildcards.

But maybe the inject.js file needs to be included in a publicly-accessible URL, which then gets sent to the translator...

查看更多
登录 后发表回答