Can't comment, so sorry this isn't a real answer ...
I'm not seeing the same results. Provided details in case anything jumps out at you as being different from how I ran it and how you are running it.
In background script (located in the extension root directory), on extension startup, both:
var temp = function (tab) {
browser.tabs.executeScript(null, { file: "src/js/asdf.js" });
};
browser.tabs.onCreated.addListener(temp);
and
browser.tabs.onCreated.addListener(function (tab) {
browser.tabs.executeScript(null, { file: "src/js/asdf.js" });
});
register correctly (no errors on startup).
The file src/js/asdf.js
exists, is the correct relative path from background.js, and contains your foo method and call.
When I create a new blank tab (which by definition cannot have content scripts attached), I see the expected error in the console (albeit from undefined
instead from background.js):
Error: Missing host permission for the tab
When I create a new blank tab with content from the beginning (i.e., context click to open a link in a new tab), I see the expected result (Executed
in the console log).
When I create a new tab from within the extension, I also see the expected result (Executed
in the console log.
Potentially relevant manifest info:
- asdf.js is not web accessible
- permissions include tabs and <all_urls>
- there are no content scripts defined in manifest.json
Running Firefox 59.0.2 (64-bit) on Mac 10.13.4
manifest.json
and set that file aswebaccessible
, did you try that? – KatushaexecuteScript
is optional, you can remove thenull
. About theweb_accessible_resources
, it is not mentionned on the executeScript page and at least in FF48 it wasn't necessary. – Keniakenilworth