Skip to content

Instantly share code, notes, and snippets.

@bradjasper
Created November 6, 2013 21:56
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 bradjasper/7344793 to your computer and use it in GitHub Desktop.
Save bradjasper/7344793 to your computer and use it in GitHub Desktop.
This tests aborting font files from Google web fonts. This works as expected.
var page = require('webpage').create();
// Block fonts
var abort_content_types = [
"application/x-font-woff",
"font/woff",
"font/opentype",
];
// Default user agent won't work with TypeKit
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.0; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7';
page.onResourceRequested = function(resourceData, res) {
if (abort_content_types.indexOf(resourceData["contentType"]) != -1) {
console.log("Found contentType we should abort = " + resourceData["contentType"]);
res.abort();
}
};
page.onResourceReceived = function(res) {
if (abort_content_types.indexOf(res["contentType"]) != -1) {
console.log("ERROR: Should have aborted content, but received it = " + res["contentType"]);
}
}
page.open('https://developers.google.com/fonts/docs/getting_started', function () {
page.render('google.png');
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment