Requests leaks before cancel or redirect at chrome.webRequest.onBeforeRequest

1,149 views
Skip to first unread message

Mo Li

unread,
May 23, 2015, 5:02:16 AM5/23/15
to chromium-...@chromium.org
I tried to redirect or cancel some requests with onBeforeRequest, but I found that some requests (looks like type === "main_frame") will be sent before callback function called .

Sachin Jain

unread,
May 23, 2015, 5:53:33 AM5/23/15
to Mo Li, chromium-...@chromium.org
@Mo Li I have been using the same API for more than 1 year now and it does not hold true to me.
Can we have a look at the code ?
Or just tell me the request Url which you are trying to redirect/block.

Just for example, You can have a look at this [0].



On Sat, May 23, 2015 at 2:32 PM, Mo Li <lym...@gmail.com> wrote:
I tried to redirect or cancel some requests with onBeforeRequest, but I found that some requests (looks like type === "main_frame") will be sent before callback function called .

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/66045d85-a806-4e9d-b9d0-79dfecbae711%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Mo Li

unread,
May 23, 2015, 6:35:09 AM5/23/15
to chromium-...@chromium.org, lym...@gmail.com
Thanks for reply, here is an example to block bing.com, I can sure that it sent request to bing.com more than one times. maybe include dns resolve, I'm not sure.

Linux x86_64, Google Chrome 43.0.2357.65 (Official Build) (64-bit).

    chrome.webRequest.onBeforeRequest.addListener(function(details) {
        var url = details.url;
        var type = details.type;
        //Test: block bing.com.:
        if (new RegExp("^https?://([^/]*?\.)?bing\.com").test(url)) {
            //    alert("debug:\n" + url + "\n" + type);
            return {
                cancel : true
            };
        }
    }, {
        urls : ["http://*/*", "https://*/*"]
    }, ["blocking"]);




On Saturday, May 23, 2015 at 5:53:33 PM UTC+8, Sachin Jain wrote:
@Mo Li I have been using the same API for more than 1 year now and it does not hold true to me.
Can we have a look at the code ?
Or just tell me the request Url which you are trying to redirect/block.

Just for example, You can have a look at this [0].


On Sat, May 23, 2015 at 2:32 PM, Mo Li <lym...@gmail.com> wrote:
I tried to redirect or cancel some requests with onBeforeRequest, but I found that some requests (looks like type === "main_frame") will be sent before callback function called .

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

Sachin Jain

unread,
May 23, 2015, 6:58:09 AM5/23/15
to Mo Li, chromium-...@chromium.org
Instead of returning { cancel:true } , Can you try this

{code}
return { redirectUrl: 'javascript:' }
{code}

Once again same reference, but different line

Let me know if it works out for you. I am pretty sure it should.
BTW there are multiple Chrome Extensions out there which you can use to achieve this :)


On Sat, May 23, 2015 at 4:05 PM, Mo Li <lym...@gmail.com> wrote:
Thanks for reply, here is an example to block bing.com, I can sure that it sent request to bing.com more than one times. maybe include dns resolve, I'm not sure.

Linux x86_64, Google Chrome 43.0.2357.65 (Official Build) (64-bit).

    chrome.webRequest.onBeforeRequest.addListener(function(details) {
        var url = details.url;
        var type = details.type;
        //Test: block bing.com.:
        if (new RegExp("^https?://([^/]*?\.)?bing\.com").test(url)) {
            //    alert("debug:\n" + url + "\n" + type);
            return {
                cancel : true
            };
        }
    }, {
        urls : ["http://*/*", "https://*/*"]
    }, ["blocking"]);




On Saturday, May 23, 2015 at 5:53:33 PM UTC+8, Sachin Jain wrote:
@Mo Li I have been using the same API for more than 1 year now and it does not hold true to me.
Can we have a look at the code ?
Or just tell me the request Url which you are trying to redirect/block.

Just for example, You can have a look at this [0].


On Sat, May 23, 2015 at 2:32 PM, Mo Li <lym...@gmail.com> wrote:
I tried to redirect or cancel some requests with onBeforeRequest, but I found that some requests (looks like type === "main_frame") will be sent before callback function called .

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Mo Li

unread,
May 23, 2015, 7:36:21 AM5/23/15
to chromium-...@chromium.org, lym...@gmail.com
Finally I found it, it's my mistake. I enabled "Prefetch resources to load pages more quickly" in chrome settings. that's why it will send request before onBeforeRequest.
I have this problem a week ago, I almost give up.
  Thanks for your help.

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Sachin Jain

unread,
May 23, 2015, 7:39:17 AM5/23/15
to Mo Li, chromium-...@chromium.org
Cool you solved the problem..Glad to help :)

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
Reply all
Reply to author
Forward
0 new messages