Closed
Bug 870324
Opened 12 years ago
Closed 7 years ago
Provide a way of interaction between scripts added in two different contentScriptFile blocks
Categories
(Add-on SDK Graveyard :: General, defect, P3)
Add-on SDK Graveyard
General
Tracking
(Not tracked)
RESOLVED
INCOMPLETE
People
(Reporter: prageck, Unassigned)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22
Steps to reproduce:
I need to add some scripts (base libraries) to a webpage which would attach a dropdown menu with every textarea on the page. I succeeded in doing so using the pageMod method.
I also want to load some more scripts later on, which would be based on user's interaction with the dropdown. I injected these scripts using the tabs.attach method.
The problem is I want the base libraries to interact with these newly loaded scripts.
Actual results:
The scripts that are loaded later on do not recognize the base libraries.
Expected results:
I know it is due to security reasons that scripts loaded using two different contentScript can not interact with each other. However, it would be nice if we could implement a way to do this without posing a threat to security issues.
Can you attach your add-on code to the bug?
Flags: needinfo?(prageck)
Reporter | ||
Comment 2•12 years ago
|
||
Hey Wes,
Here is what I am trying to do
pageMod.PageMod({
include: "*",
contentStyleFile: self.data.url("css/jquery.ime.css"),
contentScriptFile: [ self.data.url("js/jquery.js"),
self.data.url("js/jquery.ime.js"),
self.data.url("js/jquery.ime.selector.js"),
self.data.url("js/jquery.ime.preferences.js"),
self.data.url("js/jquery.ime.inputmethods.js"),
self.data.url("js/invoke.jquery.ime.js")
],
onAttach: function(worker) {
worker.port.on( "injectScript", function ( imeSource ) {
worker = tabs.activeTab.attach({
contentScriptFile: [ self.data.url(imeSource)]
});
worker.port.emit( "scriptInjected", imeSource );
} );
},
});
I am trying to implement a firefox addon for this demo:
http://thottingal.in/projects/js/jquery.ime/examples/
When you click in the textarea, you will see a keyboard icon at the bottom that allows a user to enter text in the language of his/her choice.
The first five scripts will build the UI. When the user selects a particular language, I need to inject the script for that particular language to the page, and the newly injected script should be able to interact with the scripts injected earlier.
Flags: needinfo?(prageck)
Comment 3•12 years ago
|
||
Wes, I talked in the past days with Praveen Singh, and I think has a valid use case: basically he has 150 scripts and of course he doesn't want to inject all of them, but only the ones related to the language the user choose (see the demo).
Unfortunately, this scripts needs the base libs to work. And they manipulate the DOM: now, if you include the base script using PageMod, and then the additional script using `tab.attach`, the problem is in resulting in two different sandbox (a worker for PageMod, and a worker for the tab.attach), so they can't see each other. Plus, because the base libs modifying the DOM they can't be included twice (add them also when users inject the language scripts) without resulting in some unexpected behaviors.
As side note, it seems also that in Google Chrome it works as the OP expected, because executing script in a tab always end up in the same "isolated world".
Here my two cents:
1. We could have a way to evaluate scripts passed with `tab.attach` in an existing worker. This is also how Google Chrome seems to work under the hood, in our case we could opt-in:
PageMod({
include: "*",
contentScriptFile: data.url("jquery.js")
});
And then:
tab.attach({
contentScriptFile: data.url("a-jquery-plugin.js"),
worker: worker
});
Where `worker` is this case is one returned by `pageMod.onAttach`, or another `tab.attach` call.
2. Instead of adding high level API options, we could do that using low level API, something like:
const { load } = require("sdk/content/worker");
load(worker, data.url("a-jquery-plugin.js");
That actually is needed under the hood to provide the 1st solution. Basically the difference is if we want to expose that functionality as high level API or not.
Comment 4•12 years ago
|
||
of course it was:
load(worker, data.url("a-jquery-plugin.js"));
I missed a bracket. However, this is already a functionality I had in mind since I wrote my "overlay" stuff for PageMod; and is needed also to integrate this such functionality without any hack.
Would Irakli's content script JEP cover your needs? https://github.com/mozilla/addon-sdk/wiki/JEP-Content-scripts
Flags: needinfo?(prageck)
Comment 6•12 years ago
|
||
I don't think so, but of course we can extend the JEP to cover it. As far as I understood, the content script JEP provides a way to execute the same script in different context (e.g. page-mod, tab); where here the needs is execute different scripts in the same context.
Reporter | ||
Comment 7•12 years ago
|
||
Hey Wes,
As Matteo pointed out and as far as I understood the content script JEP, I think it would allow to execute a content script in different APIs (pageMod, tab.attach etc).
But in my use case, I would like to execute different content scripts in different APIs (pageMod and tab.attach in my case), and also these content scripts (loaded in pageMod and tab.attach) should be able to see each other.
Can we include this requirement in the JEP itself?
Flags: needinfo?(prageck)
Flags: needinfo?(rFobic)
Comment 8•12 years ago
|
||
Can you elaborate why exactly you want two content scripts to share same context ? It seems like in majority cases that wouldn't be desired. As of you're specific scenario above it feels like just having a way tell to content-srcipt host that you wish more scripts to be loaded into it would solve the problem.
If that is a case, I think it should not be a big deal to add `script.load(url)` that would enable you to load more scripts into it later on.
Flags: needinfo?(rFobic) → needinfo?(prageck)
Reporter | ||
Comment 9•12 years ago
|
||
Hi Irakli,
The scripts that need to be loaded later consists of certain rules/patterns/data about a specific language that the user selected (see demo http://thottingal.in/projects/js/jquery.ime/examples/).
The baselibs (loaded initially that manipulate the DOM) need to access these rules/patterns/data in order to convert the text from English to the language that the user selected.
That is why I need these two content scripts to share the same content.
I hope the explanation is clear enough. Let me know if I'm missing out on something.
Flags: needinfo?(prageck)
Comment 10•12 years ago
|
||
> Praveen
In that case I presume that `script.load(data.url("my-other.js"))` will address that case isn't it ?
Priority: -- → P3
Comment 11•7 years ago
|
||
Add-on SDK is no longer supported so resolving bugs as INCOMPLETE
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → INCOMPLETE
You need to log in
before you can comment on or make changes to this bug.
Description
•