【发布时间】:2016-11-05 15:21:50
【问题描述】:
window.onerror=function(err,url,line){
if(err=='boom'){
console.log(true);
}
else{
console.log(false);
}};
console.error('boom');
这会输出undefined!
如何在 java 脚本中判断错误包含什么文本?
我正在尝试检测 google chrome cast 扩展错误
加载资源失败:net::ERR_ADDRESS_UNREACHABLE chrome-extension://boadgeojelhgndaghljhdcfkmllpafd/cast_sender.js
相关:Google chrome cast sender error if chrome cast extension is not installed or using incognito
我的理由是
//tried to detect chromecast extension id: boadgeojelhgndaghljhdicfkmllpafd
//it looks like it is protected from detection (tried: http://blog.kotowicz.net/2012/02/intro-to-chrome-addons-hacking.html)
//if they are using:
//chrome flash ===flash (needs double click as &autoplay=1 lets the user do only one click but it side-effects with no video preview)
//chrome chromeCast===fastjs (google are being bad players here!)
//chrome ===slowjs (almost unusable website)
//chrome flash chromeCast===flash ffsake! (maybe try one video then see if there are errors and put a cookie, chromecast=true means that we got no errors so we don't need flash!) todo:how to analyse error text?
//if the user is on chrome and does not have flash then they are youtubes 'exception'! they will have very crap loading times
var chrome=0;
if(/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)){
chrome=1;
function detectPlugin(substrs){
if(navigator.plugins){
for(var i=0,l=navigator.plugins.length;i<l;i++){
var plugin=navigator.plugins[i]
, haystack=plugin.name+plugin.description
, found=0;
for(var j=0;j<substrs.length;j++){
if(haystack.indexOf(substrs[j])!=-1){found++;}
}
if(found==substrs.length){return true;}
}}
return false;
}
var detectFlash=[/*"Shockwave",*/"Flash"]; //not entirely sure how relevant shockwave is here
if(detectPlugin(detectFlash)){chrome=2;}
}
然后我创建一个 iframe:
'https://www.youtube.com/'+(chrome==2?'v':'embed')+'/'+ytvidcode
ytvidcode 是 youtube 视频的 ID
v 用于已折旧的闪存嵌入,而embed 用于 html5(损坏/wont fix)嵌入
所以上面的代码会检测到 chrome 然后会尝试检测 flash 但无法检测到 chrome-cast。
如果用户同时拥有 chrome-cast 和 flash(因为它无法检测到 chrome-cast/chrome-cast 错误),它将强制使用 flash(如果存在)。
如果 Flash 不存在,那么用户将获得糟糕的 youtube 嵌入体验(他们可能不得不使用其他浏览器)
是否有可能检测到 chrome-cast 造成的错误或任何其他存在的痕迹?
因为如果它是一个已安装的扩展,那么它应该被充分利用,因为闪存已贬值
window.onerror=function(e,url,line){console.dir(arguments);}//nope
window.onerror=function(e,url,line){console.dir(this);}//nope
https://github.com/Valve/fingerprintjs2
new Fingerprint2().get(function(result, components){
console.log(result); //a hash, representing your device fingerprint
console.log(components); // an array of FP components
});
components[13] ("regular_plugins") 显示没有 Google cast,即使我今天已经安装了它
此时我唯一能想到的就是计时加载他们的一个视频(如果他们在 chome 上并且加载测试视频的时间太长,那么他们一定没有 chrome cast),使用这个https://developers.google.com/youtube/iframe_api_reference#Getting_Started 和一个计时器和一个 cookie 之后(所以测试只发生一次)... 我会测试这个然后也许会报告回来
【问题讨论】:
标签: javascript google-chrome-extension youtube