如何在隐身模式下启用我的 chrome 扩展程序? [英] How can I enable my chrome extension in incognito mode?
本文介绍了如何在隐身模式下启用我的 chrome 扩展程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为 Google Chrome 创建了一个扩展程序,想知道是否可以在隐身模式下启用我的扩展程序.
I created an extension for Google Chrome and would like to know if it is possible for my extension to be enabled in incognito mode.
例如:chrome.extension ...... allowedIncognitoAccess = true
推荐答案
Chrome 扩展程序无法自动激活隐身模式.
It's not possible to automatically activate incognito mode for Chrome extensions.
与其让用户找出可以找到该选项的位置,不如指示用户选中扩展程序中的复选框.
Instead of letting the user figure out where the option can be found, just instruct the user to put a check on the checkbox at the extension.
- 要检测是否启用了隐身,请使用
chrome.extension.isAllowedIncognitoAccess
方法. - 向用户显示说明后,使用
chrome.tabs.创建
或chrome.tabs.update
打开chrome://extensions/?id=YOUR EXTENSION ID HERE
.可以通过chrome.runtime.id以编程方式读取扩展 ID代码>
属性.Chrome 识别id
查询参数并在扩展列表中突出显示指定的扩展,如下图所示(注意灰色背景):
- To detect whether incognito is enabled, use the
chrome.extension.isAllowedIncognitoAccess
method. - After showing the instructons to the user, use
chrome.tabs.create
orchrome.tabs.update
to openchrome://extensions/?id=YOUR EXTENSION ID HERE
. The extension ID can be read programatically through thechrome.runtime.id
property. Chrome recognizes theid
query parameter and highlights the specified extension in the list of extensions, as seen in the next picture (notice the gray background):
在代码方面:
chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess) {
if (isAllowedAccess) return; // Great, we've got access
// alert for a quick demonstration, please create your own user-friendly UI
alert('Please allow incognito mode in the following screen.');
chrome.tabs.create({
url: 'chrome://extensions/?id=' + chrome.runtime.id
});
});
这篇关于如何在隐身模式下启用我的 chrome 扩展程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文