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 6934583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:58:46+00:00 2026-05-27T11:58:46+00:00

I’m developing an extension where I need to get the entire text content on

  • 0

I’m developing an extension where I need to get the entire text content on the current tab. Now I’ve a plugin which retrieves selected text from the current tab. So, in essence I’m looking for the ctrl-A version of it :). This is what I’ve done so far taking the hint from @Derek.

This is in my event handler(this is just one, there are other listeners too for onUpdated etc):

chrome.tabs.onSelectionChanged.addListener(function(tabId,changeInfo,tab) {
  chrome.tabs.getSelected(null,function(tab) {
    chrome.tabs.sendRequest(tab.id, {method: "getSelection"}, function (response) {
      selectedtext = response.data;
    });
    chrome.tabs.sendRequest(tab.id, {method: "getText"}, function (response) {
      alltext = response.data;
    });
  });
});

This is what I’ve written in the content script:

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
  if (request.method == "getSelection")
    sendResponse({data: window.getSelection().toString()});
  else if (request.method == "getText")
    sendResponse({data: document.body.innerText});
  else 
    sendResponse({});
});

However the document.body.innerText is returning undefined. I need the entire text of the current tab in alltext. Can someone help me out on this?
Thanks.

  • 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-27T11:58:46+00:00Added an answer on May 27, 2026 at 11:58 am

    You can use document.body.innerText or document.all[0].innerText to do it in the content script.
    It will get all the text content in the page, without any HTML code.

    Or you can use document.all[0].outerHTML to get the HTML of the whole page.


    Example

    In the Content Script

    function getText(){
        return document.body.innerText
    }
    function getHTML(){
        return document.body.outerHTML
    }
    console.log(getText());             //Gives you all the text on the page
    console.log(getHTML());             //Gives you the whole HTML of the page
    

    Added

    So you want the content script to return the text to the popup. You can use:

    • chrome.tabs.getSelected to get the tab selected,
    • chrome.tabs.sendRequest to send request to the content script,
    • and chrome.extension.onRequest.addListener to listen to requests.

    Popup page

    chrome.tabs.getSelected(null, function(tab) {
        chrome.tabs.sendRequest(tab.id, {method: "getText"}, function(response) {
            if(response.method=="getText"){
                alltext = response.data;
            }
        });
    });
    

    Content Script

    chrome.extension.onRequest.addListener(
        function(request, sender, sendResponse) {
            if(request.method == "getText"){
                sendResponse({data: document.all[0].innerText, method: "getText"}); //same as innerText
            }
        }
    );
    

    This should work.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.