如何在Chrome扩展中静默取消webRequest [英] How to cancel webRequest silently in chrome extension

查看:295
本文介绍了如何在Chrome扩展中静默取消webRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里重新发布了来自Chromium-extensions google group的问题。

I'm re-posting my question from Chromium-extensions google group here.

在我的扩展中,我想取消一些基于url模式的webRequest。我的问题是,如果我在 onBeforeRequest 事件侦听器中返回 {cancel:true} ,浏览器将重定向到一个页面,告诉我该请求被某个扩展阻止。但我只是想默默取消请求(因为什么也没有发生)。

In my extension, I want to cancel some webRequests based on url pattern. My problem is that, if I return {cancel:true} in the onBeforeRequest event listener, the browser would redirect to a page telling me that the request is blocked by some extension. But I just want to cancel the request silently(as nothing happened).

我也试着返回 {redirectUrl:} onBeforeRequest 事件侦听器中,控制台会记录一个错误,指出不是有效的URL,并且浏览器底部出现一个条,说:等待扩展。要解散该栏,我然后在该网页中运行内容脚本 window.stop()。这有时会起作用,但并非总是如此。所以我想知道是否有人有更好的解决方案。感谢!!

I have also tried to return {redirectUrl:""} in the onBeforeRequest event listener, the console would log an error saying that "" was not a valid URL, and a bar appeared at the bottom of the browser, saying "Waiting for extension". To dismiss that bar, I then run content script "window.stop()" in that web page. That works sometimes, but not always. So I wonder if someone has any better solution. Thanks!!

推荐答案

您应该使用javascript:url来代替:

You should use "javascript:" url instead :

{
    redirectUrl:"javascript:"
}

这篇关于如何在Chrome扩展中静默取消webRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆