Conditionally load script content into Safari extension, for example, in FF / Chrome?

I am writing a fairly complex browser extension for Chrome, Firefox and Safari.

In Chrome and Firefox, I can specify which script content is injected into which sites based on URL match.

Safari does not offer any such (fine-grained) functions - they only allow one white / black list for all sites.

Is there any way to do this? If not, how can I conditionally load a Javascript file? (bearing in mind, I cannot add them to the DOM).

I tried yepnope , but it is added to the DOM.

Note. I do not want to add logic to the actual files, since they are essentially library code that is duplicated over extensions.

+3
source share
2 answers

safari.extension.addContentScriptand safari.extension.addContentScriptFromURLallow you to programmatically embed scripts. You can use these methods on your global page, on the extension, or on the extension panel. For both methods, the arguments are:

  • a script for input (as a string or URL, respectively),
  • whitelist of URL patterns for matching pages to which you want to enter the script,
  • blacklist to exclude pages and
  • boolean for entering the script as the end of the script (or as the beginning of the script).

For more information, see this page in the Safari extensions reference.

, URL-, ( ) UNIX , . .

+9

, , , Chrome Firefox. SafariExtension :

. . script , . script, Info.plist, .

- Scripts Info.plist.

+3

All Articles