1

Problem Definition

I'm trying to develop a Firefox Add-on using Firefox SDK. I've problem with emitting add-on preference to the external script (ins.js) in ./data folder. I've read lots of questions about these problems but I can't implement my code how to change this. I know that my problem will be solve with worker and port objects but I need a little bit help.

Note: I don't make a bookmark add-on and I know other API's about bookmarking operations. Please do not advice about bookmark API.

[main.js]

function handleClick(state) {
    var accInf = require("sdk/simple-prefs").prefs.bookmarklet;
    accInf = accInf.substring(208, 220);
    console.log(accInf)

    require("sdk/tabs").activeTab.attach({
        contentScriptFile: [self.data.url("ins.js")]
    });
}

accInf is variable that I want to emit to ins.js and accesing it as a variable or assigning another variable.

[ins.js]

 function makechange() {
        //function body
       // that recives a variable defined in pref by user and accessing (or assigning other variable) this  variable to make some jobs. 
 }

[package.json]

"preferences": [{
    "name": "bookmarklet",
    "title": "Some title is here!",
    "description": "....",
    "type": "string",
    "value": "please enter value"
}]

What I Want to Do

I'm trying to emit a variable (accInf) which defined by user as a pref (bookmarklet) to the ins.js and accessing in ins.js scope. How can I change the code in ins.js and index.js to solving this problem?

Related Questions Which I Found Before I Ask This Question

Firefox SDK access preferences from content script

Use of simple-prefs (SDK API) with external script and postMessage

Community
  • 1
  • 1
mathema
  • 939
  • 11
  • 22
  • those related questions pretty much give you the code you need, any answer should be almost identical to those – Jaromanda X Nov 14 '15 at 10:39
  • what may not be clear to you is that `tab.attach` returns a worker object - see https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs#attach%28options%29 ... you can communicate with the injected script using `worker.port.on/emit` in `main.js` (where `worker` is returned from `...activeTab.attach(...` - and `self.port.on/emit` in `inj.js` – Jaromanda X Nov 14 '15 at 10:48
  • You said that ` I know that my problem will be solve with worker and port objects`. A simple-example implementation of ports is in developers guide of firefox: https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/using_port. You can integrate this directly to your code. Why are you asking the question? – Christos Papoulas Nov 14 '15 at 10:51

0 Answers0