Since their introduction, NoScript's Script Surrogates (or "Surrogate Scripts") have grown both in reliability and flexibility. NoScript 2.1.3 introduced two new types of surrogates (“Before script" and "After script"), so it's a good time to recap.

Script Surrogates replace a blocked script or complements existing scripts which would not work as expected because of NoScript.

A Script Surrogate is defined by a pair about:config string entries:

  1. "noscript.surrogate.surrogate_name.replacement" contains the JavaScript code to be executed.
  2. "noscript.surrogate.surrogate_name.sources" is a URL pattern matching the origin(s) of the scripts to be replaced or complemented.
  3. "noscript.surrogate.surrogate_name.exceptions" is a URL pattern which, if matched, prevents the surrogate from being triggered even if sources matches too.

Various built-in surrogates can be looked up for reference by opening about:config and typing noscript.surrogate. inside the filter box.

Source URL patterns may be prefixed with one or more special characters (<, >, @ and !), which determine the type and behavior of the matching surrogate.

Here's a quick reference of the available surrogate types grouped by source prefix, courtesy of long time contributor al_9x:

  • no prefix
    - blocked script surrogate

    • matches blocked scripts
    • runs only if page is script allowed
    • runs when the blocked matched script would have
  • '<'
    - before script surrogate

    • matches allowed scripts
    • runs only if page and script are allowed
    • runs just before the matched script executes
  • '>'
    - after script surrogate.

    • matches allowed scripts
    • runs only if page and script are allowed
    • runs just after (load event) the matched script executes
  • '@'
    - script allowed page (html document) surrogate

    • matches script allowed pages
    • runs only if the page is script allowed
    • runs before HTML parsing starts
  • '!'
    - script blocked page surrogate

    • matches script blocked pages
    • runs only if the page is script blocked
    • runs on DOMContentLoaded
  • '!@'
    - page surrogate

    • matches pages
    • runs on both script allowed and script blocked pages
    • runs on DOMContentLoaded

2 Responses to “Script Surrogates Quick Reference”

  1. #1 AnonymousCoward says:

    Nice contribution al_9x :-)
    While I'd never be able to write my own surrogates, it's
    always good to be able to audit your own config with some basic information - rather than have to ask every question from first principles. Saves everyone a lot of time that way.

  2. #2 Deborah says:

    Thank you for volunteering with FireFox and providing tools to help us. Since loosing my job, I've been volunteering and I wonder if I could barter the $15.00 with you somehow. I'm certified in special education, K-12 counselling, and I'm a licensed social worker. Part of my responsibilities while working, was helping young people "find themselves" academically, socially, intellectually, etc. and how they "fit" into the world of work/education. Working with adults, spanned an entirely different sphere, from occupational to existential. I've written many papers/reports/and completed one grant.

    If there is something in my qualification that could be bartered at $15.00, let me know. Thank you! Take care .... Peace

Bad Behavior has blocked 850 access attempts in the last 7 days.