Parameters to browser.tabs.executeScript()

Talk about add-ons and extension development.
Post Reply
Martin2011
Posts: 5
Joined: October 2nd, 2011, 2:38 am

Parameters to browser.tabs.executeScript()

Post by Martin2011 »

Hello,

According to the Mozilla documentation at https://developer.mozilla.org/en-US/Add ... cuteScript this function should take 2 parameters and returns a Promise, meaning you should do something like this:

Code: Select all

browser.tabs.executeScript(tab_id, { file: 'script.js' }).then(function(result) {
    alert('Script injected');
});
However when I inject my script using this syntax it is rejected because my JS script happens to have a function at the end which is not structured clonable (to be precise, the script consists of nothing more than a single function which is called by another script I also inject).

Now obviously I could just add a line to the end of my script reading "true;" but that seems horrible.

Altermatively, if I use the following syntax (which is the same as chrome's syntax) then it works fine:

Code: Select all

browser.tabs.executeScript(tab_id, { file: 'script.js' }, function(result) {
    alert('Script injected');
});
I don't have to add any redundant code hacks to the end of my script, it is inherently nicer and better.

However obviously here I am using a third parameter (the callback function) which is not mentioned in the Mozilla documentation.

So my question is this:

Is calling with 3 parameters completely valid or is it just luck that it works and it could stop working any moment?

Thanks,

Martin
Post Reply