简体   繁体   中英

How to regconize incognito mode and open new tab in an existing incognito window?

i am not professional developer. and i just make one Chrome extension app. https://chrome.google.com/webstore/detail/%EB%84%A4%EC%9D%B4%EB%B2%84-%EA%B2%80%EC%83%89/bkkebjanfcchfakehopacbbpogflmdie?utm_source=chrome-ntp-icon

This app just makes CONTEXT MENU and open window new chrome tab. but one of my user wants me to make this app works in incognito mode. (open window with incognito mode)

i really tried many times. but i can`t understand how to recognize incognito mode and how to make new incognito tab in same window. This is my last try and please help me... thanks

chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess) 
{
 if (isAllowedAccess) return;
  window.open("http://search.naver.com/search.naver?ie=utf8&query=" + itemData.selectionText, '_blank');
});

The context menu listener receives a tab object in the second parameter so let's reuse its windowId property via chrome.tabs.create :

chrome.contextMenus.onClicked.addListener((info, tab) => {
  chrome.tabs.create({
    url: 'http://search.naver.com/search.naver?ie=utf8&query=' +
      encodeURIComponent(info.selectionText),
    windowId: tab.windowId,
    openerTabId: tab.id,
  });
});

PS With openerTabId , when this new tab will be closed by the user, the focus will be automatically set to the specified tab regardless of its relative position in the tab strip.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM