Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7194217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:19:36+00:00 2026-05-28T20:19:36+00:00

This is not just for Google Chrome extension but also for JavaScript I am

  • 0

This is not just for Google Chrome extension but also for JavaScript

I am writing a Chrome extension in which when a text is highlighted and a context menu is shown I display my item in the context menu which when clicked should process the selected text.

After bringing up the context menu and selecting my option I get empty object with all values zeros and nulls..

So I want to implement some mechanism which will buffer the text selection as soon as the user releases the mouse after selecting the text so that an event can fire and if anything fires I can make a copy of the selected text in a global variable and can process later.

window.getSelected() is working fine when I tested with a separate testing code but while using with my extension where I bring up the context menu I could not get the actual selected text.

The selected text as I see in documentations would be of text and html.

Suggestions please…


Here I have pasted what I am doing. When I click save to word reminder I get an empty string:

enter image description here

and here is the rest of the code:

<script>
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {


    switch(request.message)
    {
        case 'getSelection':
            sendResponse({data: window.getSelection().toString()});
        break;
        
        case 'createMenu':
            seecon();
            break;
        
        default:
            sendResponse({data: 'Invalid arguments'});
        break;
    }
});

function conOnClick(info,tab)
{

/*
    chrome.extension.sendRequest(tab.id, {method: 'getSelection'}, function(response){
        alert(response.data);
    });
*/  
}


//function seecon()
{
var contexts = ["selection"];
for (var i = 0; i < contexts.length; i++) {
  var context = contexts[i];
  var title = "Save to Word Reminder";
  var id = chrome.contextMenus.create({"title": title, "contexts":[context],
                                       "onclick": conOnClick});
  
}

}



</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:19:37+00:00Added an answer on May 28, 2026 at 8:19 pm

    I would simply set a mouseUp event on the document, and then check if there is any selection (and if yes, whether the selection is different from the previous selection).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To learn JavaScript I am writing a small text editor Google Chrome extension. But
Google's not coming to my rescue, here, and I just know this is the
This may sound like a stupid question but I'm a beginner not just to
This is not really a question because I just solved the problem, but I
This might not have a major usecase in projects, but I was just trying
I'm on Win XP but this problem occurs on Firefox, IE, and Google Chrome.
It just appears like this in Google Chrome: <html> <head> <title>Hello World!</title> </head> <body>
This is not really an issue, because the code works, but I am just
How can I update this regular expression to find and replace not just /news/
There's something wrong with my code or I'm just not understanding this fully. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.