Skip to content

Instantly share code, notes, and snippets.

@Osmose
Last active September 20, 2017 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Osmose/d59da84e9531487e5210cc0444f3eab9 to your computer and use it in GitHub Desktop.
Save Osmose/d59da84e9531487e5210cc0444f3eab9 to your computer and use it in GitHub Desktop.
Testing Filter Expressions in the Browser Console
  1. Open the DevTools and go into the settings via the Gear Icon

  2. Ensure "Enable browser chrome and add-on debugging toolboxes" is checked.

  3. Open the browser console

    • Tools > Web Developer > Browser Console
    • Cmd + Shift + J
  4. Run the following in the console:

    Cu.import("resource://shield-recipe-client/lib/RecipeRunner.jsm", {}).RecipeRunner.checkFilter({
      id: 1,
      arguments: {},
      filter_expression: FILTER_TO_TEST,
    }).then(result => console.log(result))

    For example:

    Cu.import("resource://shield-recipe-client/lib/RecipeRunner.jsm", {}).RecipeRunner.checkFilter({
      id: 1,
      arguments: {},
      filter_expression: 'true',
    }).then(result => console.log(result))

    You can use backticks for multi-line expressions:

    Cu.import("resource://shield-recipe-client/lib/RecipeRunner.jsm", {}).RecipeRunner.checkFilter({
      id: 1,
      arguments: {},
      filter_expression: `
        (
          true &&
          normandy.country == "US"
        )
      `,
    }).then(result => console.log(result))
  5. The console will output a Promise object, and then log true or false depending on whether the expression passed for your client or not.

Notes

  • Certain filters, particular filters that involve normandy.recipe, may not work as expected, as they rely on the id and arguments fields passed in.
  • If you are using time-based or geolocation-based filters, which rely on the Normandy service, this method may fail if you've configured Firefox to point towards a local instance of Normandy which is not running.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment