2

I am working on an extension for Facebook that hides the activity (e. g. last active 20 minutes ago). Therefore, I am trying to redirect the requests of the form

https://0-p-06-ash2.channel.facebook.com/pull?idle=2&state=active&

to requests of the form

https://0-p-06-ash2.channel.facebook.com/pull?idle=50000&

using the webRequest API, onBeforeRequest. Now, when I try my redirection technique on a local test page I have made myself, where I send an ajax request and subsequently redirect it using the plugin, it works perfectly. The network inspector shows me the first request as pending, and a new request is then added. The data the ajax call receives is correct, i. e. what the second request should return.

When the plugin runs on Facebook, however, the first request is not shown as pending, but it is cancelled instead, and no second request is sent at all.

This is the code I use (approximately):

var callback = function(details){

    var ajaxURL = details.url;

    if(ajaxURL.indexOf('pull?channel') > -1){ // find activity log request

        var newURL = ajaxURL.replace('&state=active', '').replace(/idle\=[0-9]{0,}/gi, 'idle=50000');

        return {redirectUrl: newURL};

    }

    return {cancel: false};

}

filter = {urls: ["<all_urls>"]};

chrome.webRequest.onBeforeRequest.addListener(callback, filter, ["blocking"]);

It appears to me that Facebook finds a way of detecting redirection before the request is actually sent, yet according to this question on Stackoverflow, it's not supposed to be possible.

So how do they do it, and how can I circumvent it? Thanks in advance.

Community
  • 1
  • 1
arik
  • 28,170
  • 36
  • 100
  • 156

0 Answers0