如何在隐身模式下启用我的 chrome 扩展程序? [英] How can I enable my chrome extension in incognito mode?

查看:51
本文介绍了如何在隐身模式下启用我的 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.

  • To detect whether incognito is enabled, use the chrome.extension.isAllowedIncognitoAccess method.
  • After showing the instructons to the user, use chrome.tabs.create or chrome.tabs.update to open chrome://extensions/?id=YOUR EXTENSION ID HERE. The extension ID can be read programatically through the chrome.runtime.id property. Chrome recognizes the id 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屋!

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