Parameters to browser.tabs.executeScript()

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

Post Posted January 13th, 2018, 1:53 pm


According to the Mozilla documentation at ... 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?



Return to Extension Development

Who is online

Users browsing this forum: No registered users and 1 guest