是否可以通过用户脚本确定Chrome是否处于隐身模式? [英] Is it possible to determine if Chrome is in incognito mode via a user-script?

查看:171
本文介绍了是否可以通过用户脚本确定Chrome是否处于隐身模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前问过这个问题

a>,但没有说清楚我的意思是用户脚本,而不是来自网页的JavaScript。所以我现在会更清楚。



有没有可能通过用户脚本确定Google Chrome是否处于隐身模式(基本上,脚本作为浏览器中的扩展名运行,而不是在网页上运行的脚本)?

解决方案

如果您正在开发扩展程序,那么您可以使用选项卡API来确定窗口/标签页是否隐身。 更多信息可以在 code.google.com 上找到。



如果您只是使用网页或使用者脚本,这并不容易,而且它的设计就是这样。但是,我注意到,在incongnito中,所有试图打开数据库(window.database)都会失败,这是因为在隐身模式下,用户机器上不允许留下任何数据。



我没有测试过它,但我怀疑所有对localStorage的调用都会失败。


I asked this question before but didn't make it clear that I meant in user script, not in JavaScript from a webpage.So I'll be more clear now.

Is it possible to determine if Google Chrome is in incognito mode via a user-script (basically a script run as an extension in the browser, not a script being run on a webpage)?

解决方案

If you are developing an Extension then you can use the tabs API to determine if a window/tab incognito.

More information can be found on code.google.com.

If you are just working with a webpage or a userscript, it is not easy, and it is designed to be that way. However, I have noticed that all attempts to open a database (window.database) fail when in incongnito, this is because when in incognito no trace of data is allowed to be left on the users machine.

I haven't tested it but I suspect all calls to localStorage fail too.

这篇关于是否可以通过用户脚本确定Chrome是否处于隐身模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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