Tips for identifying incognito mode and launching a fresh tab within an already open incognito window

I may not be a professional developer, but I created a Chrome extension app. You can check it out here: Link to Chrome Extension

This app currently adds a context menu and opens a new tab in Chrome. However, one of my users has asked me to make the app work in incognito mode as well (i.e., open tabs with incognito mode).

I have tried several times, but I am struggling to figure out how to detect incognito mode and how to open a new incognito tab within the same window. This is my final attempt, so please help me out... Thank you.

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

Answer №1

When interacting with the context menu listener, we are provided with a specific tab object as the second parameter. Utilizing this, we can make use of its windowId property in conjunction with 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,
  });
});

In addition, by setting the openerTabId, the new tab will automatically refocus on the specified tab when closed by the user, disregarding its position in the tab strip.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

After refreshing the page, users are redirected back to the login page

On my website, I created a main page and an index.html page that redirects to the main page through a login panel. The issue I am encountering is that when I log in successfully on the main page and then refresh the page, it takes me back to the login pag ...

What is the best way to deliver flash messages using Express 4.0?

Currently, my web application requires authentication, and I am encountering an issue with the signup page. If a user tries to sign up with an email that is already in the database, I want to display an error message. Here is the code snippet I am using on ...

Updating form values when a radio button is changed using asynchronous JavaScript and XML (AJ

Here is the form I have created: <form method="post" action="options.php" id="pay_what_you_want_form"> <input type="radio" name="payment_period" value="monthly" id="monthly" checked><label for="monthly" class="payment_period_label"> ...

Retrieving a JSON object based on its name

Here is the structure of a JSON object I am working with: [ { "filters": [ { "name": "category", "list": [ { "category-abc": { "title": "abc", "number": "2" ...

Uploading JSON data to my database using PHP and Sendgrid

Trying to establish a connection with SendGrid using curl commands and then utilize a foreach loop to store the results in my database. However, I am encountering an undefined index error for both username and password, as well as an invalid argument withi ...

Implementing append operations in JavaScript without relying on the id attribute

Is there a way to specify the second div without assigning it an ID or using any attributes, and then perform an append operation inside it? For instance, indicating that the p element should be appended within the second div without relying on an ID or ...

Accept incoming JSON data

Currently, I am utilizing $routeProvider to establish a route as shown below: when('/grab/:param1/:param2', { controller: 'someController', templateUrl: "templates/someTemplate.html", }). Within the someController, I can acce ...

The JSX snippet accurately displays the expected value on some pages, but displays an incorrect value on other pages

{_id === friendId || <IconButton onClick={() => patchFriend() } sx={{ backgroundColor: primaryLight, p: "0.6rem" }} > {isFriend ? ( <PersonRemoveOutlined sx={{ color: primaryDark }} /> ...

Deliver Compressed Files following Angular CLI --Prod Configuration

After using the Angular CLI's command to minify my basic Angular app, a dist folder was generated with the project folder and minified files. However, when I run ng serve, it always serves the unminified development files, whether it's in the roo ...

AngularJS factory architecture for multiple functions

It's not the exact data I'm using in my project, but I'm simplifying it for demonstration purposes. In my AngularJS app, I have a factory like this: myApp.factory('inputinfo', function () { var self = { test: function (in) { ...

Determine the exact location where the mouse was clicked on a webpage containing an iframe

I am trying to retrieve the mouse position on my HTML page, but I am encountering some issues. Here's what I have so far: document.onclick = function(click) { if (click.clientX<340){ myControl.inputs.selection = false; btnRotate.remove ...

Is it possible to duplicate native functions in JavaScript, such as window.alert or document.write?

I am looking to replace all instances of the alert function in my code with a custom alert message saying "you used alert". var hardCodedAlert = alert; //Although I understand this won't work. What other approach can I take? window.alert=function(){ ...

Having trouble with the automatic closing feature of Bootstrap drop down in React?

While using the drop button feature of Bootstrap, I have encountered a situation where it works fine when clicked on, but disabling it by clicking outside using autoClose='outside' does not seem to work as expected. When I click on my hamburge ...

developing a dynamic structure that can store multiple levels of data

I am grappling with the task of creating a multidimensional array in JavaScript to send data via an Ajax call to PHP. My expertise in JS is limited, especially when it comes to this particular task... I have shared the code on JSFiddle The desired struct ...

Encountered a problem with sending values using jQuery and JSON: Unexpected token 'b'

Can you explain why in this specific scenario there is an error showing up as SyntaxError: Unexpected token b listados:229? response = '{"name":"John"}'; var obj = jQuery.parseJSON(response); $.ajax({ url:urlform, dataType: ...

A guide on utilizing webpack devServer proxy within a create react app

Currently, I am in the process of developing a new application with create-react-app and I am looking to incorporate some proxies into my code. In the past, I utilized webpack's devServer for this purpose. module.exports = { ... devServer: { ...

Issues with sending emails through Nodemailer in a Next.js project using Typescript

I'm currently working on a personal project using Nodemailer along with Next.js and Typescript. This is my first time incorporating Nodemailer into my project, and I've encountered some issues while trying to make it work. I've been followin ...

Unable to retrieve the complete count of invitations made by a user

My goal is to retrieve the invites of the author of a specific command within one server. I have experimented with various solutions, but many appear outdated or incorrect. Here is my current approach: exports.run = async (client, message, args) => { ...

Transmit the JSON Data file through an AJAX request

I am encountering an issue where the HttpPostedFileBase is null when trying to send an image file to a Controller. I have attempted entering image: image outside of JSON.stringify({}), but it did not work. Additionally, I tried changing the contentType f ...

Looking for a modular approach? Incorporate specific parts of a module into the parent component

Developing a node.js module and aiming to organize my code effectively. My goal is to have individual files/folders for different parts of the module such as authentication, users, etc. These will be required from a parent package which will then expose t ...