Loading content scripts into iframes from extensions?

3,577 views
Skip to first unread message

johnjbarton

unread,
Dec 9, 2011, 1:05:06 PM12/9/11
to Chromium-extensions
I want to communicate with a Web app over window.postMessage. I guess
it is possible:
Web app loads my iframe
My iframe uses DOM to contact content-script
content-script uses chrome.extension to contact background process.
Then JSON messages can move from background process to web app.

However I am stuck on the first step: the ideal address for 'my
iframe' is from the chrome extension. I can load an iframe from eg
chrome-extension://pajdciblphmekmjnhjkloaiepfcdiiba/iframe.html
but I cannot attach the content-script to this page because the scheme
is no http, https, nor file:.

The only other solution I can find is to put the iframe on a web
server, but that makes the system much more complex.

Any ideas?
jjb

Mihai Parparita

unread,
Dec 9, 2011, 8:36:44 PM12/9/11
to johnjbarton, Chromium-extensions
Perhaps I'm misunderstanding something, but why do you need to inject a content script into a frame that is served by your extension? If you control the contents of the iframe, you can directly include the content script in it.

Mihai


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Luke

unread,
Dec 13, 2011, 6:02:05 AM12/13/11
to Chromium-extensions
If your iframe document is page in your extension then it already has
every functionality of ordinary extension page in example pageAction,
optionsAction etc. Content Script is used ONLY on documents outside of
your extension. You don;t need to use Content Script on your extension
iframe, you have in default full API. In my extension im using 3
scripts:
- background.html - with control code
- contentFrontend - to have access to document DOM, and later to
create iframe element with src to iframe.html page that is inside my
extension
- iframe.html - has whole UI to interact with user and what is
important with this i can ensure full isolation of JS and CSS.
All pages are connected to background page with named connections via
chrome.extension.connect({name:"channelName"}), all connections are
returning sender.tab.id so you can locate current tab context.

Cheers

On Dec 10, 2:36 am, Mihai Parparita <mih...@chromium.org> wrote:
> Perhaps I'm misunderstanding something, but why do you need to inject a
> content script into a frame that is served by your extension? If you
> control the contents of the iframe, you can directly include the content
> script in it.
>
> Mihai
>

> On Fri, Dec 9, 2011 at 10:05 AM, johnjbarton <johnjbar...@johnjbarton.com>wrote:
>
>
>
>
>
>
>
> > I want to communicate with a Web app over window.postMessage. I guess
> > it is possible:
> >  Web app loads my iframe
> >  My iframe uses DOM to contact content-script
> >  content-script uses chrome.extension to contact background process.
> >  Then JSON messages can move from background process to web app.
>
> > However I am stuck on the first step: the ideal address for 'my
> > iframe' is from the chrome extension.  I can load an iframe from eg
> >  chrome-extension://pajdciblphmekmjnhjkloaiepfcdiiba/iframe.html
> > but I cannot attach the content-script to this page because the scheme
> > is no http, https, nor file:.
>
> > The only other solution I can find is to put the iframe on a web
> > server, but that makes the system much more complex.
>
> > Any ideas?
> > jjb
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.

> > To post to this group, send email to chromium-extensi...@chromium.org.


> > To unsubscribe from this group, send email to

> > chromium-extensions+unsubscr...@chromium.org.

Reply all
Reply to author
Forward
0 new messages