Is there any way to replace content's JS function from add-on ? - Mozilla

This is a discussion on Is there any way to replace content's JS function from add-on ? - Mozilla ; Hi, I have a page, I have to work to from my add-on and it contains errorneous javascript functions. Is there any way to replace it from my add-on? I tried something like this, but with no success: var win ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Is there any way to replace content's JS function from add-on ?

  1. Is there any way to replace content's JS function from add-on ?

    Hi,

    I have a page, I have to work to from my add-on and it contains
    errorneous javascript functions.

    Is there any way to replace it from my add-on? I tried something like
    this, but with no success:

    var win = content.frames[1];

    alert(win); // shows XPCNativeWrapper[object Window]

    alert(win['formatoFecha']); // shows 'undefined', but such a function
    presents in the frame, for sure.

    win['formatoFecha'] = function (fecha) {
    if (fecha==null)
    return "";
    else {
    var anio=fecha.getYear();
    if (anio<200) anio=1900+anio;
    return fecha.getDate()+"-"+(fecha.getMonth()
    +1)+"-"+anio;
    }
    };

    alert(win['formatoFecha']); // shows assigned value, but page still
    use old function.

    Any ideas?

    Thanks in advance.
    --
    WBR,
    Serge.


  2. Re: Is there any way to replace content's JS function from add-on ?

    On 19 ΣΕΞ, 11:31, Nickolay Ponomarev wrote:

    > http://www.google.com/search?q=xpcna...CNativeWrapper


    I did it, sure :-)

    http://groups.google.com/group/mozil...sg/3ba40f23b0b...

    Thanks, I'll try to play with Sandbox functionality

    --
    WBR,
    Serge

  3. Re: Is there any way to replace content's JS function from add-on ?

    Hi John, thanks for the reply.

    > You attached the function to the wrapper, not the window.

    Yes, I got it. I'd better to ask how to bypass XPCNativeWrapper and
    get to "native" window. I'll try to play with Sandbox functionality as
    Nikolay suggested.

    > The operation
    > of writing on the win object from the extension is supposed to be
    > illegal. However it is allowed, only it does not alter the page. It does
    > alter the wrapper, so that is why the last alert works. I think it is a
    > design flaw: I think the operation ought to fail.

    Agreed. The only reason why I'm trying to do it is - that bloody page
    isn't under my control and my add-on have to work with it.

    --
    WBR,
    Serge.

+ Reply to Thread