Is it possible to have arguments in callbacks sent to a exported function

Manuel Reimer manuel.reimer at gmx.de
Sat Aug 5 09:22:43 UTC 2017


Hi Martin

Thank you for your help.
I was able to resolve my problem with "cloneInto".

Manuel

On 08/05/2017 10:56 AM, Martin Giger wrote:
> Hi Manuel
> 
> The reason the object can't be accessed by the callback is that, like
> the function, it is created in the context of the content script and
> thus not allowed to be used by the page unless explictly exported. What
> you'd have to do here is to use the cloneInto() function[1] on the
> object before passing it to the callback.
> 
> Martin
> 
> [1]:
> https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts#cloneInto
> 
> 
> On 05.08.2017 10:47, Manuel Reimer wrote:
>> Hello,
>>
>> I just want to add, that I'm able to use "JSON.stringify" and pass the
>> stringified object to the callback. I'm able to recreate the
>> javascript object from there.
>> That's ugly but works...
>> But I'm still interested why I'm not able to pass a object or array
>> directly.
>>
>> Manuel
>>
>> On 08/05/2017 10:28 AM, Manuel Reimer wrote:
>>> Hello,
>>>
>>> in my WebExtension, I export a function from "content script" to the
>>> page javascript like so:
>>>
>>>
>>> function Test(aCallback) {
>>>     var my_return = {test: "test"};
>>>     aCallback(my_return);
>>> }
>>> exportFunction(Test, window, {defineAs: "my_addon_test"});
>>>
>>>
>>> I export a function and this function is expected to get a callback
>>> function from page javascript. I want to pass a javascript object as
>>> parameter to this callback.
>>>
>>> If I try to do so, I get the following in browser console as soon as
>>> I try to access the javascript object from my page script:
>>>
>>>
>>> Permission denied to access property Symbol.toPrimitive
>>>
>>>
>>> Is there any *secure* way to do what I need? Is there any way to pass
>>> a parameter to such callback functions?
>>>
>>> Thanks in advance
>>>
>>> Manuel
>>> _______________________________________________
>>> Dev-addons mailing list
>>> Dev-addons at mozilla.org
>>> https://mail.mozilla.org/listinfo/dev-addons
>>
>> _______________________________________________
>> Dev-addons mailing list
>> Dev-addons at mozilla.org
>> https://mail.mozilla.org/listinfo/dev-addons
> 
> 
> 
> 
> _______________________________________________
> Dev-addons mailing list
> Dev-addons at mozilla.org
> https://mail.mozilla.org/listinfo/dev-addons
> 



More information about the Dev-addons mailing list