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

Commit

Permalink
Fix twitter.com redirect to mobile.twitter.com with block scripts
Browse files Browse the repository at this point in the history
Fix #2884

Auditors: @srirambv

Test Plan:
1. clean session store
2. go to twitter.com, turn on block scripts
3. twitter.com should not redirect to mobile
  • Loading branch information
diracdeltas authored and bbondy committed Sep 29, 2016
1 parent 588706d commit 509fbdb
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions app/siteHacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,16 @@ module.exports.init = () => {
}
}

// This filter only applies to top-level requests, so details.url == mainFrameUrl
let domain = URL.parse(details.url).hostname.split('.').slice(-2).join('.')
let hack = siteHacks[domain]
let customCookie
let cancel
const mainFrameUrl = Filtering.getMainFrameUrl(details)
// this can happen if the tab is closed and the webContents is no longer available
if (!mainFrameUrl) {
return {
resourceName: module.exports.resourceName
}
}
const firstPartyUrl = URL.parse(mainFrameUrl)
if (hack && hack.onBeforeSendHeaders) {
const result = hack.onBeforeSendHeaders.call(this, details)
if (result && result.customCookie) {
customCookie = result.customCookie
} else if (Filtering.isResourceEnabled(appConfig.resourceNames.NOSCRIPT, firstPartyUrl) &&
} else if (Filtering.isResourceEnabled(appConfig.resourceNames.NOSCRIPT, 'https://twitter.com/') &&
result && result.cancel) {
// cancel is only called on Twitter where noscript is enabled
cancel = true
Expand All @@ -63,11 +56,10 @@ module.exports.init = () => {
resourceName: module.exports.resourceName
}
}
const firstPartyUrl = URL.parse(mainFrameUrl)
if (hack && hack.onBeforeRequest &&
(hack.enableForAll ||
hack.enableForAdblock && Filtering.isResourceEnabled(appConfig.resourceNames.ADBLOCK, firstPartyUrl) ||
hack.enableForTrackingProtection && Filtering.isResourceEnabled(appConfig.resourceNames.TRACKING_PROTECTION, firstPartyUrl))) {
hack.enableForAdblock && Filtering.isResourceEnabled(appConfig.resourceNames.ADBLOCK, mainFrameUrl) ||
hack.enableForTrackingProtection && Filtering.isResourceEnabled(appConfig.resourceNames.TRACKING_PROTECTION, mainFrameUrl))) {
const result = hack.onBeforeRequest.call(this, details)
if (result && result.redirectURL) {
redirectURL = result.redirectURL
Expand Down

1 comment on commit 509fbdb

@srirambv
Copy link
Collaborator

Choose a reason for hiding this comment

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

++
Tested on the build(509fbdb). Doesn't redirect to mobile site.

Please sign in to comment.