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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:06:44+00:00 2026-05-23T08:06:44+00:00

I have injected a content script file to all pages and inner iframes using

  • 0

I have injected a content script file to all pages and inner iframes using "all_frames": true but when I send a request from popup only top window is receiving it. Any idea how can send it to all inner frames or at least last focused window/document?

Popup.html (page action):
===========
chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.sendRequest(tab.id, {...}, function(response) {...});
});

content_script.js
=================
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    sendResponse({...});
});

I have checked that content script is working in inner frames.

I’m trying to retrieve text selection which may be in inner frames.

(By the way I prefer not to open connection by every and all content script, that’s a big overhead.)

  • 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-23T08:06:45+00:00Added an answer on May 23, 2026 at 8:06 am

    The problem is that one tab can have only one onRequest listener. So if you want to send messages to only iframe script, and there is only one iframe on the page, then you should create a listener inside iframe only:

    //listen to requests only inside iframe
    if(window!=window.top) {
        chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
            ...
        });
    }
    

    Now if you want to send requests to both parent page and iframe, or there are many iframes on the page that need to listen to requests – you need to communicate through ports.

    Ports still have a similar limitation – only one port listener will be called, but you can open many ports. If there is a parent page with only one iframe – you just open two connections on two different ports. But if there are many iframes on the page, and each iframe has subframes – you would need to enumerate all iframes first to create unique ports for each of them.

    PS. I am not sure what you meant by

    I prefer not to open connection by every and all content script

    but if you want to inject content script on demand, there is chrome.tabs.executeScript().

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

Sidebar

Related Questions

Im trying to have my code to be injected using the content script method
Can I inject a CSS file programmatically using a content script js file? It
I have the following file file: <html> <head> <title></title> <script type=text/javascript src=/Prototype.js></script> <script type=text/javascript>
I'm having some issues with a content script being injected to the same page
I have a bean in which I've injected an HttpServletRequest using the @Autowired annotation
We have some JavaEE5 stateless EJB bean that passes the injected EntityManager to its
I have a DOM element in memory that is yet to be injected in
I have a pretty standard Repository pattern going, where repositories are injected into my
I have a website, and I just discovered that somehow someone injected JavaScript on
Have just started using Google Chrome , and noticed in parts of our site,

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.