3

Is there any way to easily use a remote javascript file as a content script with the page-mod API?

I am trying to build some simple addons for my own use to automate some repetitive stuff. Because the pages I will be modding change from time to time, and I will need to be updating the "content script" javascript accordingly, it would be nice if I only had to edit it on my server and the addon/extension would work again without editing and repacking the xpi. I'm pretty sure I would be able to hack something together that will accomplish this, but if there is any easy way to do it I'm all ears :)

1 Answer 1

5

The content script itself should never be a remote script, that would be a security vulnerability. But the content script can insert a remote script into the web page:

var pageMod = require("page-mod");
pageMod.PageMod({
  include: "...",
  contentScript: 'var script = document.createElement("script");'+
                 'script.src = "...";'+
                 'document.body.appendChild(script);'
});
Sign up to request clarification or add additional context in comments.

3 Comments

You can do this, Wladimir is correct; but I don't think it would be approved by AMO editors fwiw.
@ztatic: Not sure, I've seen extensions that do that kind of thing. As long as this is done for only one site and there are no large privacy concerns (e.g. not an online banking site or generally a site containing sensitive data) this might be accepted. But it is still a questionable approach of course, the user needs to trust you that this script doesn't suddenly change into something evil (e.g. because you need money urgently or because your server has been hacked).
Wow, I am also amazed AMO would approve ANY addon that uses this technique for release to millions of users. For the exact reasons Wladimir mentioned... As mentioned above, this implementation is only for my own use, so no worries on that stuff in this instance. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.