Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Stub googletagservices.com to fix nfl.com/videos
Browse files Browse the repository at this point in the history
Fix #1528

Auditors: diracdeltas
  • Loading branch information
bbondy committed May 10, 2016
1 parent 5ff874e commit c1e061b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function registerForBeforeRequest (session) {
return
}

let redirectURL
for (let i = 0; i < beforeRequestFilteringFns.length; i++) {
let results = beforeRequestFilteringFns[i](details)
if (!module.exports.isResourceEnabled(results.resourceName)) {
Expand All @@ -101,16 +100,17 @@ function registerForBeforeRequest (session) {
return
}
if (results.redirectURL) {
redirectURL = results.redirectURL
// Show the ruleset that was applied and the URLs that were upgraded in
// siteinfo
if (results.ruleset) {
BrowserWindow.getAllWindows().forEach((wnd) =>
wnd.webContents.send(messages.HTTPSE_RULE_APPLIED, results.ruleset, details))
}
cb({redirectURL: results.redirectURL})
return
}
}
cb({redirectURL: redirectURL})
cb({})
})
}

Expand Down
21 changes: 18 additions & 3 deletions js/data/siteHacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const urlParse = require('url').parse
const base64Encode = require('../lib/base64').encode

// Polyfill similar to this: https://github.com/gorhill/uBlock/blob/de1ed89f62bf041416d2a721ec00741667bf3fa8/assets/ublock/resources.txt#L385
const googleTagManagerRedirect = 'data:application/javascript;base64,' + base64Encode(`(function() { var noopfn = function() { ; }; window.ga = window.ga || noopfn; })();`)
// Polyfill similar to this: https://github.com/gorhill/uBlock/blob/de1ed89f62bf041416d2a721ec00741667bf3fa8/assets/ublock/resources.txt#L257
const googleTagServicesRedirect = 'data:application/javascript;base64,' + base64Encode(`(function() { var p; var noopfn = function() { }; var noopthisfn = function() { return this; }; var noopnullfn = function() { return null; }; var nooparrayfn = function() { return []; }; var noopstrfn = function() { return ''; }; var companionAdsService = { addEventListener: noopthisfn, enableSyncLoading: noopfn, setRefreshUnfilledSlots: noopfn }; var contentService = { addEventListener: noopthisfn, setContent: noopfn }; var PassbackSlot = function() { }; p = PassbackSlot.prototype; p.display = noopfn; p.get = noopnullfn; p.set = noopthisfn; p.setClickUrl = noopthisfn; p.setTagForChildDirectedTreatment = noopthisfn; p.setTargeting = noopthisfn; p.updateTargetingFromMap = noopthisfn; var pubAdsService = { addEventListener: noopthisfn, clear: noopfn, clearCategoryExclusions: noopthisfn, clearTagForChildDirectedTreatment: noopthisfn, clearTargeting: noopthisfn, collapseEmptyDivs: noopfn, defineOutOfPagePassback: function() { return new PassbackSlot(); }, definePassback: function() { return new PassbackSlot(); }, disableInitialLoad: noopfn, display: noopfn, enableAsyncRendering: noopfn, enableSingleRequest: noopfn, enableSyncRendering: noopfn, enableVideoAds: noopfn, get: noopnullfn, getAttributeKeys: nooparrayfn, refresh: noopfn, set: noopthisfn, setCategoryExclusion: noopthisfn, setCentering: noopfn, setCookieOptions: noopthisfn, setLocation: noopthisfn, setPublisherProvidedId: noopthisfn, setTagForChildDirectedTreatment: noopthisfn, setTargeting: noopthisfn, setVideoContent: noopthisfn, updateCorrelator: noopfn }; var SizeMappingBuilder = function() { }; p = SizeMappingBuilder.prototype; p.addSize = noopthisfn; p.build = noopnullfn; var Slot = function() { }; p = Slot.prototype; p.addService = noopthisfn; p.clearCategoryExclusions = noopthisfn; p.clearTargeting = noopthisfn; p.defineSizeMapping = noopthisfn; p.get = noopnullfn; p.getAdUnitPath = nooparrayfn; p.getAttributeKeys = nooparrayfn; p.getCategoryExclusions = nooparrayfn; p.getDomId = noopstrfn; p.getSlotElementId = noopstrfn; p.getSlotId = noopthisfn; p.getTargeting = nooparrayfn; p.getTargetingKeys = nooparrayfn; p.set = noopthisfn; p.setCategoryExclusion = noopthisfn; p.setClickUrl = noopthisfn; p.setCollapseEmptyDiv = noopthisfn; p.setTargeting = noopthisfn; var gpt = window.googletag || {}; var cmd = gpt.cmd || []; gpt.apiReady = true; gpt.cmd = []; gpt.cmd.push = function(a) { try { a(); } catch (ex) { } return 1; }; gpt.companionAds = function() { return companionAdsService; }; gpt.content = function() { return contentService; }; gpt.defineOutOfPageSlot = function() { return new Slot(); }; gpt.defineSlot = function() { return new Slot(); }; gpt.disablePublisherConsole = noopfn; gpt.display = noopfn; gpt.enableServices = noopfn; gpt.getVersion = noopstrfn; gpt.pubads = function() { return pubAdsService; }; gpt.pubadsReady = true; gpt.sizeMapping = function() { return new SizeMappingBuilder(); }; window.googletag = gpt; while ( cmd.length !== 0 ) { gpt.cmd.push(cmd.shift()); } })();`)

module.exports = {
'forbes.com': {
Expand Down Expand Up @@ -53,14 +59,23 @@ module.exports = {
$('.player-overlay, .player-loading').hide();`
},
'www.googletagmanager.com': {
onBeforeRequest: function(details) {
onBeforeRequest: function(details) {
if (urlParse(details.url).pathname !== '/gtm.js') {
return
}
return {
// Block / polyfill similar to this: https://github.com/gorhill/uBlock/blob/de1ed89f62bf041416d2a721ec00741667bf3fa8/assets/ublock/resources.txt#L385
redirectURL: 'data:application/javascript,(function() { var noopfn = function() { ; }; window.ga = window.ga || noopfn; })();'
redirectURL: googleTagManagerRedirect
}
}
},
'www.googletagservices.com': {
onBeforeRequest: function(details) {
if (urlParse(details.url).pathname !== '/tag/js/gpt.js') {
return
}
return {
redirectURL: googleTagServicesRedirect
}
}
}
}
5 changes: 5 additions & 0 deletions js/lib/base64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

module.exports.encode = (input) => new Buffer(input).toString('base64')

1 comment on commit c1e061b

@diracdeltas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.