Closed Bug 943718 Opened 11 years ago Closed 10 years ago

Add attachTo in tabs.attach

Categories

(Add-on SDK Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: gcaiazzo, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36

Steps to reproduce:

I attempted to utilize tabs.attach to get a content script inside the active tab and also any frames within that tab (no other tabs regardless of url/includes, etc).


Actual results:

tabs.attach only put the content script into the top level in the active tab, not any potential frames.


Expected results:

We should be able to specify an "attachTo" similar to page-mods and specify top and/or frame for the active tab and get content scripts in those respective areas.
Flags: needinfo?(rFobic)
I don't quite understand the last update to this bug. Is more information needed from me or someone else?
Irakli flagged himself for more info so he remembers to respond to this bug when he has more time.
I understand. Thank you all and if there is anything else I can do, please let me know.
Hi gcaiazzo,

Actual plan is to make idea of a page-mod little more flexible so that modification could be attached
to different targets, which could include tabs, location patterns etc...
We even had a JEP for that https://github.com/mozilla/addon-sdk/wiki/JEP-Content-scripts

That should enable creating let script = new ContentScript({ url: url }); script.attach(tab) we should
probably consider attaching to nested frames as well, although it's generally best to avoid doing that,
cause overhead introduced can be exponential. In general it's better to manually access windows of the child iframes from the content script and do whatever you need. That significantly minimizes overhead.

I'm also kind of curious about the use case, maybe we can offer something that is less inefficient while
solving problem gracefully.
Flags: needinfo?(rFobic)
I don't believe I was ever able to access elements within frames when attaching to a tab with tabs.attach. I am using jquery and the common frame/iframe selector bits were not working like I have had them work in the past with other environments. I even tried various other approaches, but perhaps I missed something.
(In reply to gcaiazzo from comment #5)
> I don't believe I was ever able to access elements within frames when
> attaching to a tab with tabs.attach. I am using jquery and the common
> frame/iframe selector bits were not working like I have had them work in the
> past with other environments. I even tried various other approaches, but
> perhaps I missed something.

Maybe you can show some code snippets illustrating what is that you're trying to do.
You could access iframe content as follows:

document.querySelector("iframe").contentWindow

Obviously you may wanna access specific iframe instance and not just a first one
like shown above.
Status: UNCONFIRMED → RESOLVED
Closed: 10 years ago
Flags: needinfo?(rFobic)
Resolution: --- → FIXED
Flags: needinfo?(rFobic)
Can someone explain how this is resolved?

My use case is an SWF scanner. SWF files can be added anytime, maybe even in response to events (button click). So not knowing when the SWF is loaded on a page, the best way for me to do my scan in response to a "scan" button.

When user clicks the button, I attach a script to the current tab that searches for embed/object tags. To that extent, all's great. Many sites, however, place SWFS inside iframes, and my scanner can't access these iframes in any way.
I'd say a simple "attachTo" option for tabs would solve the problem "top", "frame" being the options.
Any updates on this issue?
I solved it through window.postMessage between the parent and child iframes. I injected an event handler for message using page-mod inside all windows/iframes.
You need to log in before you can comment on or make changes to this bug.