accessing page js objects from the addon code - Mozilla

This is a discussion on accessing page js objects from the addon code - Mozilla ; Hello all, Newby question! I have to write a function on my plugin that acces a javascript object defined on a web page. That object is a hash and its defined on the begining of a js included in the ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: accessing page js objects from the addon code

  1. accessing page js objects from the addon code

    Hello all,

    Newby question!
    I have to write a function on my plugin that acces a javascript object
    defined on a web page. That object is a hash and its defined on the
    begining of a js included in the header of the page:

    imageList = {};

    During the lifecycle of the page that object wont be empty anymore and
    when the user clicks a button or something on my plugin I'll grab that
    information and process it.

    The problem is that I cant find it. I have a reference to the document
    and the window. I tried

    window.imageList
    (that works on firebug's console)

    but all I get is that imageList is not defined, null etc.

    I'm sure I'm accessing the main window object (I use the code I found
    here:
    https://developer.mozilla.org/en/Wor...a_child_window).

    I'm not even sure this is a good thing to do...
    Can anyone give me a hint on that one?

    thanks
    marcel

  2. Re: accessing page js objects from the addon code


    I read
    https://developer.mozilla.org/en/Cod...ivileged_pages

    but the problem is that I'm not the owner of the web application I'm
    trying to get the data from so I can't do that. I can't trigger a
    custom event from the page...
    I understand that evaluating, executing javascript code from a alien
    page can have security issues. I'll do my best to prevent them (use
    the Components.utils.evalInSandbox function etc..) but for the moment
    I have to at least learn how to acces this object.

    Why he is not available from the main window object?


    m


    On Mar 16, 6:52*pm, Eric Jung wrote:
    > On Mon, Mar 16, 2009 at 1:05 PM, Marcel wrote:
    > > Hello all,

    >
    > > Newby question!
    > > I have to write a function on my plugin that acces a javascript object
    > > defined on a web page. That object is a hash and its defined on the
    > > begining of a js included in the header of the page:

    >
    > > imageList = {};

    >
    > > During the lifecycle of the page that object wont be empty anymore and
    > > when the user clicks a button or something on my plugin I'll grab that
    > > information and process it.

    >
    > > The problem is that I cant find it. I have a reference to the document
    > > and the window. I tried

    >
    > > window.imageList
    > > (that works on firebug's console)

    >
    > > but all I get is that imageList is not defined, null etc.

    >
    > > I'm sure I'm accessing the main window object (I use the code I found
    > > here:

    >
    > >https://developer.mozilla.org/en/Wor...n_chrome_code#...
    > > ).

    >
    > > I'm not even sure this is a good thing to do...
    > > Can anyone give me a hint on that one?

    >
    > You need to be very careful when interacting unprivileged code (e.g.,
    > standard web pages) from privileged code (your extension) , and vice-versa.
    > You don't want to inadvertently permit web pages to do nefarious things. Use
    > this technique instead:https://developer.mozilla.org/en/Cod...ion_between_pr...
    > I've updatedhttps://developer.mozilla.org/en/Working_with_windows_in_chrome_code#...
    > to
    > point to that page.
    >
    > Eric



+ Reply to Thread