Closed
Bug 688127
Opened 13 years ago
Closed 12 years ago
Add property to provide JSON set of global variables for initial state of content scripts
Categories
(Add-on SDK Graveyard :: General, enhancement, P3)
Add-on SDK Graveyard
General
Tracking
(Not tracked)
RESOLVED
FIXED
1.8
People
(Reporter: public, Unassigned)
Details
Attaching a contentScript to a tab is like executing a function. I'd like to "call" the content scripts and pass it arbitrary (jsonable) values: // in main.js tabs.activeTab.attach({ contentScriptFile: "cs.js", data: {a: 1, b: 2} }); // in cs.js self.data.a === 1; self.data.b === 2; currently, I have to wrap all my cs.js code in a port listener to achieve the same effect, which is not ideal: // in main.js var worker = tabs.activeTab.attach({ contentScriptFile: "cs.js" }); worker.port.emit( "init", {a: 1, b: 2} ); // in cs.js self.port.on( "init", function( data ) { data.a === 1; data.b === 2; });
Whiteboard: [triage:followup]
Updated•13 years ago
|
Assignee: nobody → myk
Updated•13 years ago
|
Whiteboard: [triage:followup]
Comment 1•13 years ago
|
||
I'm not sure I would use the "function" metaphor to describe such functionality, but I do see the value of providing a set of values to a content script to initialize its state. I would just call the option something other than `data`, such as `globals`, and then define a global variable in the content script for each property of the JSON object to which `globals` is set, i.e.: // in main.js tabs.activeTab.attach({ contentScriptFile: "cs.js", globals: { a: 1, b: 2 } }); // in cs.js // a === 1 // b === 2 To create a `data` global that encapsulated several values, you would do: // in main.js tabs.activeTab.attach({ contentScriptFile: "cs.js", globals: { data: { a: 1, b: 2 } } });
Updated•13 years ago
|
Assignee: myk → nobody
Updated•13 years ago
|
OS: Linux → All
Hardware: x86 → All
Severity: normal → enhancement
Priority: -- → P3
Summary: It should be possible to "call" contentscripts with arguments → Add property to provide JSON set of global variables for initial state of content scripts
Comment 2•13 years ago
|
||
Note: the property should be called contentScriptGlobals for consistency with the other content script properties.
Reporter | ||
Comment 3•12 years ago
|
||
I sent a PR for this bug: https://github.com/mozilla/addon-sdk/pull/351
Comment 4•12 years ago
|
||
Commits pushed to master at https://github.com/mozilla/addon-sdk https://github.com/mozilla/addon-sdk/commit/f82e7c8a8f520075d198ac77479e4a225a788faf Bug 688127: Add property to provide JSON set of global variables for initial state of content scripts https://github.com/mozilla/addon-sdk/commit/0006f26a99b3b9016ac8def642e125de31b87492 Merge pull request #411 from ochameau/fix688127 Bug 688127: Add property to provide JSON set of global variables for initial state of content scripts r=@ochameau
Comment 5•12 years ago
|
||
louisremi, I ended up rebased your patch on landed it so that it can go in next release!
Target Milestone: --- → 1.8
Comment 6•12 years ago
|
||
Thanks Louis rémi for this great contribution!
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Comment 7•12 years ago
|
||
Should we consider cherry-picking this for 1.7?
Comment 8•12 years ago
|
||
Commits pushed to stabilization at https://github.com/mozilla/addon-sdk https://github.com/mozilla/addon-sdk/commit/f82e7c8a8f520075d198ac77479e4a225a788faf Bug 688127: Add property to provide JSON set of global variables for initial state of content scripts https://github.com/mozilla/addon-sdk/commit/0006f26a99b3b9016ac8def642e125de31b87492 Merge pull request #411 from ochameau/fix688127
Comment 9•12 years ago
|
||
Commits pushed to release at https://github.com/mozilla/addon-sdk https://github.com/mozilla/addon-sdk/commit/f82e7c8a8f520075d198ac77479e4a225a788faf Bug 688127: Add property to provide JSON set of global variables for initial state of content scripts https://github.com/mozilla/addon-sdk/commit/0006f26a99b3b9016ac8def642e125de31b87492 Merge pull request #411 from ochameau/fix688127
You need to log in
before you can comment on or make changes to this bug.
Description
•