Skip to content

Instantly share code, notes, and snippets.

@kzar
Last active May 17, 2016 17:42
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 kzar/f455d61db57628578367962b8c888d17 to your computer and use it in GitHub Desktop.
Save kzar/f455d61db57628578367962b8c888d17 to your computer and use it in GitHub Desktop.
Safari bug 26322821 - safari.extension.setContentBlocker breaks when passed callback function when rules aren't converted to JSON
Summary:
safari.extension.setContentBlocker does not appear to work at all when passed a callback function except if the rules are first converted to JSON. If the rules are not converted to JSON the callback is performed twice, first with an empty string and then with an Error "Extension compilation failed: Failed to parse the JSON String.". Further calls to the function with anything but JSON also causes two callbacks first an empty string and then null.
If the callback is not passed, or if the rules are converted to JSON things seem to work as I expect.
Steps to Reproduce:
safari.extension.setContentBlocker([{
"trigger": {
"url-filter": "evil-tracker\\.js"
},
"action": {
"type": "block"
}
}], function (result) { console.log("Callback", result); });
Expected Results:
Callback performed once with the result of null. Content blocking to work.
Actual Results:
Callback performed twice, firstly with an empty string "" and then with an Error "Extension compilation failed: Failed to parse the JSON String.".
Version:
OS X 10.11
Safari 9.0 (11601.1.56)
Notes:
This is hindering us supporting the content blocking API in Adblock Plus for Safari https://codereview.adblockplus.org/29340571/
Configuration:
Attachments:
@kzar
Copy link
Author

kzar commented May 17, 2016

Also reproduced with Safari Version 9.1 (11601.5.17.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment