Google chrome extension Chrome扩展webRequest故障
我很难让我的扩展重定向一些URL 这就是我试图重定向的对象:Google chrome extension Chrome扩展webRequest故障,google-chrome-extension,url-redirection,Google Chrome Extension,Url Redirection,我很难让我的扩展重定向一些URL 这就是我试图重定向的对象: <object type="application/x-shockwave-flash" id="ytp" data="http://www.youtube.com/v/GVwh8FEsWUk?start=0&version=3&autoplay=1&border=0&cc_load_policy=0&controls=0&disab
<object type="application/x-shockwave-flash" id="ytp" data="http://www.youtube.com/v/GVwh8FEsWUk?start=0&version=3&autoplay=1&border=0&cc_load_policy=0&controls=0&disablekb=1&egm=0&enablejsapi=1&hd=1&iv_load_policy=3&modestbranding=1&playerapiid=ytp&rel=0&showinfo=0&showsearch=0" width="100%" height="100%"><param name="quality" value="high"><param name="wmode" value="opaque"><param name="allowScriptAccess" value="always"><param name="allowFullScreen" value="false"><param name="bgcolor" value="#000000"></object>
events-bg.js:
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.url.indexOf("html5=1")!=-1) return {};
console.log(details.url);
return {
redirectUrl: details.url.replace("&?html5=[(true|false)01]","") + "&html5=1"
};
},
{
urls: ["http://www.youtube.com/v/*"]
},
["blocking"]
);
本质上,我的目标是在这个播放器上强制使用html5。如果这不可能以这种方式实现,我可以始终使用代码注入,并以何种方式实现。我目前的设置有什么问题
注意:当前从未触发请求侦听器。我在其中设置了断点,并使用控制台日志来测试这一点
更新:
在修改权限后,我创建了一个基本的webRequest,应该在任何url上触发,但我仍然没有得到任何结果。我只想假设这个API仍然需要一些工作,并且没有足够的文档记录来查看出了什么问题。我在我的背景页面上没有任何输出,也没有固定的URL。我将手动注入代码来更正问题,直到问题得到解决。您需要在清单文件中声明
webRequestBlocking
权限。如果是,您会看到相关的错误消息。没有看到任何错误消息。没有任何类型的消息被触发。
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.url.indexOf("html5=1")!=-1) return {};
console.log(details.url);
return {
redirectUrl: details.url.replace("&?html5=[(true|false)01]","") + "&html5=1"
};
},
{
urls: ["http://www.youtube.com/v/*"]
},
["blocking"]
);